use of com.auth0.android.jwt.JWT in project java-jwt by auth0.
the class ECDSABouncyCastleProviderTests method shouldFailECDSA256KVerificationOnInvalidJOSESignatureLength.
@Test
public void shouldFailECDSA256KVerificationOnInvalidJOSESignatureLength() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(IllegalArgumentException.class));
exception.expectCause(hasMessage(is("Last unit does not have enough valid bits")));
String jwt = ES256K_JWT.substring(0, ES256K_JWT.length() - 1);
Algorithm algorithm = Algorithm.ECDSA256K((ECPublicKey) readPublicKeyFromFile(INVALID_PUBLIC_KEY_FILE_256K, "EC"), null);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.android.jwt.JWT in project java-jwt by auth0.
the class ECDSABouncyCastleProviderTests method shouldThrowOnECDSA256KVerificationWithDERSignature.
@Test
public void shouldThrowOnECDSA256KVerificationWithDERSignature() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(SignatureException.class));
exception.expectCause(hasMessage(is("Invalid JOSE signature format.")));
String jwt = "eyJraWQiOiJteS1rZXktaWQiLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.e30.MEUCIQDaCA-xzjHBCFhyAm56je5DXgylpUncBsQTxQT7AD19zwIgEjIm3lueII2W4pC_iQR6oRMHNtgqfAzTrWnV7DPNURk";
ECPublicKey key = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256K, "EC");
Algorithm algorithm = Algorithm.ECDSA256K(key, null);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.android.jwt.JWT in project kemenu-web by afdezcl.
the class RefreshTokenIntegrationTest method aCustomerCouldRefreshAToken.
@Test
void aCustomerCouldRefreshAToken() {
HttpHeaders headers = webTestClient.post().uri("/public/refresh").body(Mono.just(RefreshTokenRequestHelper.from(generateRefreshToken())), RefreshTokenRequest.class).exchange().expectStatus().isOk().expectHeader().exists("Authorization").expectHeader().exists("JWT-Refresh-Token").expectBody().returnResult().getResponseHeaders();
String newAccessToken = headers.get("Authorization").get(0);
String newRefreshToken = headers.get("JWT-Refresh-Token").get(0);
DecodedJWT decodedAccessToken = jwtService.decodeAccessToken(newAccessToken);
DecodedJWT decodedRefreshToken = jwtService.decodeRefreshToken(newRefreshToken);
assertEquals(randomCustomer.getEmail(), decodedAccessToken.getSubject());
assertEquals(randomCustomer.getEmail(), decodedRefreshToken.getSubject());
}
use of com.auth0.android.jwt.JWT in project mapsmessaging_server by Maps-Messaging.
the class AwsJwtLoginModule method login.
@Override
public boolean login() throws LoginException {
// prompt for a user name and password
if (callbackHandler == null) {
throw new LoginException("Error: no CallbackHandler available to garner authentication information from the user");
}
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("user name: ");
callbacks[1] = new PasswordCallback("password: ", false);
try {
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[0]).getName();
char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
if (tmpPassword == null) {
tmpPassword = new char[0];
}
String token = new String(tmpPassword);
((PasswordCallback) callbacks[1]).clearPassword();
// Password should be a valid JWT
RSAKeyProvider keyProvider = new AwsCognitoRSAKeyProvider(region, poolId);
Algorithm algorithm = Algorithm.RSA256(keyProvider);
JWTVerifier jwtVerifier = JWT.require(algorithm).withAudience(clientId).build();
jwtVerifier.verify(token);
return true;
} catch (IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user");
}
}
use of com.auth0.android.jwt.JWT in project blogSpringBoot by lurenha.
the class TokenUtil method verify.
/**
* 签名验证
*
* @param token
* @return
*/
public static boolean verify(String token) {
try {
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(TOKEN_SECRET)).withIssuer("peng").build();
DecodedJWT jwt = verifier.verify(token);
// System.out.println("过期时间: " + jwt.getExpiresAt());
return true;
} catch (Exception e) {
return false;
}
}
Aggregations