use of com.auth0.jwt.exceptions in project cryptography by norkator.
the class JWT method verifyECDSA256Jwt.
/**
* Verify elliptic curve based JWT
*
* @param publicPem of key pair
* @param issuer party name
* @param token of created jwt
* @return DecodedJWT including claims
* @throws JWTVerificationException thrown if verification fails
*/
public static DecodedJWT verifyECDSA256Jwt(String publicPem, String issuer, final String token) throws JWTVerificationException, InvalidKeySpecException, NoSuchAlgorithmException {
ECKey publicKey = (ECKey) PEMToKey.getPemPublicKey(publicPem, "ECDSA");
Algorithm algorithm = Algorithm.ECDSA256(publicKey);
JWTVerifier verifier = com.auth0.jwt.JWT.require(algorithm).withIssuer(issuer).build();
return verifier.verify(token);
}
use of com.auth0.jwt.exceptions in project actframework by actframework.
the class JWTTest method fromAuth0.
private String fromAuth0() throws Exception {
JWTCreator.Builder builder = com.auth0.jwt.JWT.create();
builder.withIssuer(ISSUER);
builder.withExpiresAt(new Date(EXPIRE_AT * 1000l));
builder.withJWTId(TOKEN_ID);
builder.withClaim(KEY_USERNAME, USERNAME);
Algorithm algorithm = Algorithm.HMAC256(SECRET);
return builder.sign(algorithm);
}
use of com.auth0.jwt.exceptions in project java-docs-samples by GoogleCloudPlatform.
the class GoogleJwtClient method generateJwt.
// [START endpoints_generate_jwt_sa]
/**
* Generates a signed JSON Web Token using a Google API Service Account
* utilizes com.auth0.jwt.
*/
public static String generateJwt(final String saKeyfile, final String saEmail, final String audience, final int expiryLength) throws FileNotFoundException, IOException {
Date now = new Date();
Date expTime = new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expiryLength));
// Build the JWT payload
JWTCreator.Builder token = JWT.create().withIssuedAt(now).withExpiresAt(expTime).withIssuer(saEmail).withAudience(audience).withSubject(saEmail).withClaim("email", saEmail);
// Sign the JWT with a service account
FileInputStream stream = new FileInputStream(saKeyfile);
ServiceAccountCredentials cred = ServiceAccountCredentials.fromStream(stream);
RSAPrivateKey key = (RSAPrivateKey) cred.getPrivateKey();
Algorithm algorithm = Algorithm.RSA256(null, key);
return token.sign(algorithm);
}
use of com.auth0.jwt.exceptions in project sonar-java by SonarSource.
the class JWTWithStrongCipherCheckAuth0Test method auth0JWT.
public void auth0JWT() {
JWTVerifier nonCompliantVerifier = // Noncompliant [[sc=52;ec=68]] {{Use only strong cipher algorithms when verifying the signature of this JWT.}}
JWT.require(Algorithm.none()).withSubject(LOGIN).build();
JWTVerifier nonCompliantVerifier2 = // Noncompliant
JWT.require(none()).withSubject(LOGIN).build();
JWTVerifier nonCompliantVerifier3 = // Noncompliant
JWT.require(com.auth0.jwt.algorithms.Algorithm.none()).withSubject(LOGIN).build();
JWTVerifier compliantVerifier1 = // Compliant
JWT.require(Algorithm.HMAC256(SECRET_KEY)).withSubject(LOGIN).build();
JWTVerifier compliantVerifier2 = // Compliant
JWT.require(new JWTWithStrongCipherCheckAuth0Test.MyAlgorithm("name", "description")).withSubject(LOGIN).build();
String tokenNotSigned = JWT.create().withSubject(LOGIN).withExpiresAt(addMinutes(new Date(), 20)).withIssuedAt(new Date()).sign(// Noncompliant [[sc=13;ec=29]] {{Use only strong cipher algorithms when signing this JWT.}}
Algorithm.none());
String tokenSigned = JWT.create().withSubject(LOGIN).withExpiresAt(addMinutes(new Date(), 20)).withIssuedAt(new Date()).sign(// Compliant
Algorithm.HMAC256(SECRET_KEY));
JWTCreator.Builder builder = JWT.create().withSubject(LOGIN).withExpiresAt(addMinutes(new Date(), 20)).withIssuedAt(new Date());
// Noncompliant
String tokenSignedLater = builder.sign(Algorithm.none());
}
use of com.auth0.jwt.exceptions in project bookmark by FleyX.
the class JwtUtil method decode.
/**
* Description: 解密jwt
*
* @param token token
* @param secret secret
* @return java.util.Map<java.lang.String, com.auth0.jwt.interfaces.Claim>
* @author fanxb
* @date 2019/3/4 18:14
*/
public static Map<String, Claim> decode(String token, String secret) {
if (token == null || token.length() == 0) {
throw new CustomException("token为空:" + token);
}
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier jwtVerifier = JWT.require(algorithm).build();
DecodedJWT decodedJWT = jwtVerifier.verify(token);
return decodedJWT.getClaims();
}
Aggregations