use of com.auth0.jwt.exceptions 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()));
}
use of com.auth0.jwt.exceptions in project cryptography by norkator.
the class JWT method isVerifiedECDSA256Jwt.
/**
* Verify elliptic curve based JWT
* # this is meant for test case
*
* @param publicPem of key pair
* @param issuer party name
* @param token of created jwt
* @return boolean result
*/
public static boolean isVerifiedECDSA256Jwt(String publicPem, String issuer, final String token) throws InvalidKeySpecException, NoSuchAlgorithmException {
try {
ECKey publicKey = (ECKey) PEMToKey.getPemPublicKey(publicPem, "ECDSA");
Algorithm algorithm = Algorithm.ECDSA256(publicKey);
JWTVerifier verifier = com.auth0.jwt.JWT.require(algorithm).withIssuer(issuer).build();
verifier.verify(token);
return true;
} catch (JWTVerificationException e) {
return false;
}
}
Aggregations