use of com.auth0.Tokens in project AuthGuard by AuthGuard.
the class JwtTokenVerifierTest method validateWithJti.
@Test
void validateWithJti() {
final StrategyConfig strategyConfig = strategyConfig(true);
final JwtConfig jwtConfig = jwtConfig();
final JwtTokenVerifier jwtTokenVerifier = newVerifierInstance(strategyConfig);
final String jti = UUID.randomUUID().toString();
Mockito.when(jtiProvider.next()).thenReturn(jti);
Mockito.when(jtiProvider.validate(jti)).thenReturn(true);
final AccountBO account = RANDOM.nextObject(AccountBO.class);
final AuthResponseBO tokens = generateToken(jwtConfig, account, jti);
final Either<Exception, DecodedJWT> validatedToken = jwtTokenVerifier.verify(tokens.getToken().toString());
assertThat(validatedToken.isRight()).isTrue();
verifyToken(validatedToken.get(), account.getId(), jti, null, null);
}
use of com.auth0.Tokens in project goobi-workflow by intranda.
the class JwtHelper method verifyToken.
/**
* Verifies tokens with rotated keys. Also checks if the last rotated key is valid
*
* @param token
* @param secret
* @return
*/
private static DecodedJWT verifyToken(String token, String secret, LongSupplier currentMillisSupplier) {
long currentTime = currentMillisSupplier.getAsLong();
int maxRotations = 3;
for (int currentRotation = 0; currentRotation < maxRotations; currentRotation++) {
long rotationTime = ((currentTime - (rotationDuration * currentRotation)) / rotationDuration) * rotationDuration;
try {
DecodedJWT jwt = verifyTokenWithRotationTime(token, secret, rotationTime);
return jwt;
} catch (JWTVerificationException e) {
if (currentRotation == maxRotations - 1) {
throw e;
}
}
}
return null;
}
use of com.auth0.Tokens in project app-auth0-idprovider by enonic.
the class Auth0CallbackService method handle.
public boolean handle(final HttpServletRequest request) {
try {
final IdProviderKey idProviderKey = getIdProviderKey(request);
final AuthenticationController authController = createAuthController(idProviderKey);
final Tokens tokens = authController.handle(request);
final UserInfo userInfo = retrieveUserInfo(idProviderKey, tokens);
loginService.login(request, new UserInfoAdapter(userInfo), idProviderKey);
return true;
} catch (Exception e) {
LOG.error("Error while handling auth0 callback", e);
}
return false;
}
use of com.auth0.Tokens in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldReturnTokensOnProcessIfTokenIdTokenCodeRequestPassesIdTokenVerification.
@Test
public void shouldReturnTokensOnProcessIfTokenIdTokenCodeRequestPassesIdTokenVerification() throws Exception {
doNothing().when(tokenVerifier).verify(eq("frontIdToken"), eq(verifyOptions));
Map<String, Object> params = new HashMap<>();
params.put("code", "abc123");
params.put("state", "1234");
params.put("id_token", "frontIdToken");
params.put("access_token", "frontAccessToken");
params.put("expires_in", "8400");
params.put("token_type", "frontTokenType");
MockHttpServletRequest request = getRequest(params);
request.setCookies(new Cookie("com.auth0.state", "1234"));
TokenRequest codeExchangeRequest = mock(TokenRequest.class);
TokenHolder tokenHolder = mock(TokenHolder.class);
when(tokenHolder.getIdToken()).thenReturn("backIdToken");
when(tokenHolder.getAccessToken()).thenReturn("backAccessToken");
when(tokenHolder.getRefreshToken()).thenReturn("backRefreshToken");
when(tokenHolder.getExpiresIn()).thenReturn(4800L);
when(tokenHolder.getTokenType()).thenReturn("backTokenType");
when(codeExchangeRequest.execute()).thenReturn(tokenHolder);
when(client.exchangeCode("abc123", "https://me.auth0.com:80/callback")).thenReturn(codeExchangeRequest);
RequestProcessor handler = new RequestProcessor.Builder(client, "id_token token code", verifyOptions).withIdTokenVerifier(tokenVerifier).build();
Tokens tokens = handler.process(request, response);
// Should not verify the ID Token twice
verify(tokenVerifier).verify("frontIdToken", verifyOptions);
verify(tokenVerifier, never()).verify("backIdToken", verifyOptions);
verifyNoMoreInteractions(tokenVerifier);
assertThat(tokens, is(notNullValue()));
assertThat(tokens.getIdToken(), is("frontIdToken"));
assertThat(tokens.getAccessToken(), is("backAccessToken"));
assertThat(tokens.getRefreshToken(), is("backRefreshToken"));
assertThat(tokens.getExpiresIn(), is(4800L));
assertThat(tokens.getType(), is("backTokenType"));
}
use of com.auth0.Tokens in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldReturnEmptyTokensWhenCodeRequestReturnsNoTokens.
@Test
public void shouldReturnEmptyTokensWhenCodeRequestReturnsNoTokens() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("code", "abc123");
params.put("state", "1234");
MockHttpServletRequest request = getRequest(params);
request.setCookies(new Cookie("com.auth0.state", "1234"));
TokenRequest codeExchangeRequest = mock(TokenRequest.class);
TokenHolder tokenHolder = mock(TokenHolder.class);
when(codeExchangeRequest.execute()).thenReturn(tokenHolder);
when(client.exchangeCode("abc123", "https://me.auth0.com:80/callback")).thenReturn(codeExchangeRequest);
RequestProcessor handler = new RequestProcessor.Builder(client, "code", verifyOptions).withIdTokenVerifier(tokenVerifier).build();
Tokens tokens = handler.process(request, response);
verifyNoMoreInteractions(tokenVerifier);
assertThat(tokens, is(notNullValue()));
assertThat(tokens.getIdToken(), is(nullValue()));
assertThat(tokens.getAccessToken(), is(nullValue()));
assertThat(tokens.getRefreshToken(), is(nullValue()));
}
Aggregations