Search in sources :

Example 16 with OAuth1RequestToken

use of com.github.scribejava.core.model.OAuth1RequestToken in project pac4j by pac4j.

the class OAuthCredentialsTests method testOAuth10Credentials.

@Test
public void testOAuth10Credentials() {
    final OAuth10Credentials credentials = new OAuth10Credentials(REQUEST_TOKEN, TOKEN, VERIFIER);
    assertEquals(TOKEN, credentials.getToken());
    assertEquals(VERIFIER, credentials.getVerifier());
    final OAuth1RequestToken requestToken = credentials.getRequestToken();
    assertEquals(TOKEN, requestToken.getToken());
    assertEquals(SECRET, requestToken.getTokenSecret());
    // test serialization
    final JavaSerializationHelper javaSerializationHelper = new JavaSerializationHelper();
    final byte[] bytes = javaSerializationHelper.serializeToBytes(credentials);
    final OAuth10Credentials credentials2 = (OAuth10Credentials) javaSerializationHelper.unserializeFromBytes(bytes);
    assertEquals(credentials.getRequestToken().toString(), credentials2.getRequestToken().toString());
    assertEquals(credentials.getToken(), credentials2.getToken());
    assertEquals(credentials.getVerifier(), credentials2.getVerifier());
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) JavaSerializationHelper(org.pac4j.core.util.JavaSerializationHelper) Test(org.junit.Test)

Example 17 with OAuth1RequestToken

use of com.github.scribejava.core.model.OAuth1RequestToken in project wikidata-query-rdf by wikimedia.

the class OAuthProxyService method checkLogin.

@GET
@Path("/check_login")
public Response checkLogin(@HeaderParam("X-redirect-url") String redirectUrl) throws InterruptedException, ExecutionException, IOException, URISyntaxException {
    final OAuth1RequestToken requestToken = service.getRequestToken();
    sessions.put(requestToken.getToken(), new SessionState(requestToken, Optional.ofNullable(redirectUrl).map(URI::create)));
    String authorizationUrl = service.getAuthorizationUrl(requestToken);
    return temporaryRedirect(getAuthenticationURI(authorizationUrl)).build();
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) URI(java.net.URI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 18 with OAuth1RequestToken

use of com.github.scribejava.core.model.OAuth1RequestToken in project wikidata-query-rdf by wikimedia.

the class OAuthProxyServiceUnitTest method shouldReturnForbiddenIfTokenWasCleared.

@Test
public void shouldReturnForbiddenIfTokenWasCleared() throws Exception {
    // 1st user request for request token
    sut.checkLogin(null);
    // 2nd user request for request token. Token clearing is simulated here because our cache is
    // only allowed to hold a single value during test.
    OAuth1RequestToken requestToken = new OAuth1RequestToken("new token", "tokenSecret");
    when(mwoauthServiceMock.getRequestToken()).thenReturn(requestToken);
    when(mwoauthServiceMock.getAuthorizationUrl(requestToken)).thenReturn(AUTHORIZE_URL);
    sut.checkLogin(null);
    // 1st user request for session verification
    Response verifyResponse = sut.oauthVerify(OAUTH_VERIFIER_STR, OAUTH_TOKEN_STRING, "http://localhost");
    assertThat(verifyResponse.getStatus()).isEqualTo(FORBIDDEN.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) Test(org.junit.Test)

Example 19 with OAuth1RequestToken

use of com.github.scribejava.core.model.OAuth1RequestToken in project pac4j by pac4j.

the class OAuth10CredentialsExtractor method getOAuthCredentials.

@Override
protected OAuth10Credentials getOAuthCredentials(final WebContext context) {
    final String tokenParameter = context.getRequestParameter(OAuth10Configuration.OAUTH_TOKEN);
    final String verifierParameter = context.getRequestParameter(OAuth10Configuration.OAUTH_VERIFIER);
    if (tokenParameter != null && verifierParameter != null) {
        // get request token from session
        final OAuth1RequestToken tokenSession = (OAuth1RequestToken) context.getSessionStore().get(context, configuration.getRequestTokenSessionAttributeName(client.getName()));
        logger.debug("tokenRequest: {}", tokenSession);
        final String token = OAuthEncoder.decode(tokenParameter);
        final String verifier = OAuthEncoder.decode(verifierParameter);
        logger.debug("token: {} / verifier: {}", token, verifier);
        return new OAuth10Credentials(tokenSession, token, verifier);
    } else {
        final String message = "No credential found";
        throw new OAuthCredentialsException(message);
    }
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuthCredentialsException(org.pac4j.oauth.exception.OAuthCredentialsException) OAuth10Credentials(org.pac4j.oauth.credentials.OAuth10Credentials)

Example 20 with OAuth1RequestToken

use of com.github.scribejava.core.model.OAuth1RequestToken in project pac4j by pac4j.

the class OAuth10RedirectActionBuilder method redirect.

@Override
public RedirectAction redirect(final WebContext context) {
    try {
        final OAuth10aService service = this.configuration.buildService(context, client, null);
        final OAuth1RequestToken requestToken;
        try {
            requestToken = service.getRequestToken();
        } catch (final IOException | InterruptedException | ExecutionException e) {
            throw new HttpCommunicationException("Error getting token: " + e.getMessage());
        }
        logger.debug("requestToken: {}", requestToken);
        // save requestToken in user session
        context.getSessionStore().set(context, configuration.getRequestTokenSessionAttributeName(client.getName()), requestToken);
        final String authorizationUrl = service.getAuthorizationUrl(requestToken);
        logger.debug("authorizationUrl: {}", authorizationUrl);
        return RedirectAction.redirect(authorizationUrl);
    } catch (final OAuthException e) {
        throw new TechnicalException(e);
    }
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) TechnicalException(org.pac4j.core.exception.TechnicalException) HttpCommunicationException(org.pac4j.core.exception.HttpCommunicationException) OAuthException(com.github.scribejava.core.exceptions.OAuthException) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)30 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)24 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)22 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)21 Response (com.github.scribejava.core.model.Response)21 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)20 Scanner (java.util.Scanner)20 OAuthException (com.github.scribejava.core.exceptions.OAuthException)3 IOException (java.io.IOException)3 AsyncSimpleTask (com.codepath.utils.AsyncSimpleTask)2 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 HttpCommunicationException (org.pac4j.core.exception.HttpCommunicationException)2 OAuth10Credentials (org.pac4j.oauth.credentials.OAuth10Credentials)2 OAuthCredentialsException (org.pac4j.oauth.exception.OAuthCredentialsException)2 Uri (android.net.Uri)1 OAuthConfig (com.github.scribejava.core.model.OAuthConfig)1 Token (com.github.scribejava.core.model.Token)1 URI (java.net.URI)1