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());
}
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();
}
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());
}
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);
}
}
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);
}
}
Aggregations