use of com.auth0.jwt.Algorithm in project castlemock by castlemock.
the class JWTEncoderDecoder method createToken.
public String createToken(Map<String, String> claims) {
final Date expiresAt = getExpirationDate();
final JWTCreator.Builder builder = JWT.create().withIssuer(ISSUER).withExpiresAt(expiresAt);
claims.forEach(builder::withClaim);
return builder.sign(algorithm);
}
use of com.auth0.jwt.Algorithm in project iet-hf-2022-k-k-k-k-k-k by BME-MIT-IET.
the class JwtUtil method getDecodedJWT.
public static DecodedJWT getDecodedJWT(String authorizationHeader) {
String token = authorizationHeader.substring("Bearer ".length());
Algorithm algorithm = Algorithm.HMAC256(SecurityConfig.getSecretKey().getBytes());
JWTVerifier verifier = JWT.require(algorithm).build();
return verifier.verify(token);
}
use of com.auth0.jwt.Algorithm in project brapi-Java-TestServer by plantbreeding.
the class BrapiTestServerJWTAuthFilter method validateOAuthToken.
private String validateOAuthToken(HttpServletRequest request) {
try {
String token = request.getHeader("Authorization");
if (token != null) {
token = token.replaceFirst("Bearer ", "");
RSAPublicKey pubKey = getPublicKey(oidcDiscoveryUrl);
Algorithm algorithm = Algorithm.RSA256(pubKey, null);
JWTVerifier verifier = JWT.require(algorithm).withIssuer("https://auth.brapi.org/auth/realms/brapi").build();
DecodedJWT jwt = verifier.verify(token);
return jwt.getClaim("email").asString();
}
return null;
} catch (Exception e) {
return null;
}
}
use of com.auth0.jwt.Algorithm in project bank-of-sirius by nginxinc.
the class JWTVerifierGenerator method generateJWTVerifier.
@Bean(name = "verifier")
@ConditionalOnProperty(value = "jwt.account.authentication.enabled", matchIfMissing = true, havingValue = "true")
public JWTVerifier generateJWTVerifier(@Value("${PUB_KEY_PATH}") final String publicKeyPath) throws IOException {
// load public key from file
final Path publicKeyFile = Paths.get(publicKeyPath);
final String keyContents = new String(Files.readAllBytes(publicKeyFile));
try {
final String keyStr = keyContents.replaceFirst("-----BEGIN PUBLIC KEY-----", "").replaceFirst("-----END PUBLIC KEY-----", "").replaceAll("\\s", "");
final byte[] keyBytes = Base64.getDecoder().decode(keyStr);
final KeyFactory kf = KeyFactory.getInstance("RSA");
final X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(keyBytes);
final RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
// Initialize JWT verifier.
final Algorithm algorithm = Algorithm.RSA256(publicKey, null);
final JWTVerifier verifier = JWT.require(algorithm).build();
LOGGER.debug("Generated JWT token verifier [algorithm={},publicKeyPath={}]", algorithm.getName(), publicKeyFile);
return verifier;
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
final String msg = String.format("Cannot generate JWT key [path=%s]", publicKeyFile);
throw new GenerateKeyException(msg, e);
}
}
use of com.auth0.jwt.Algorithm in project kikaha.rocker by jmilagroso.
the class Security method valid.
/**
* Validates token
* @param token The token string parameter.
* @param id The id string/integer parameter.
* @param claim The claim string parameter.
* @param issuer The issuer string parameter.
* @return boolean Is valid.
*/
public boolean valid(String token, String id, String claim, String issuer) {
boolean valid = false;
try {
verifier = JWT.require(algorithm).withJWTId(id).withClaim("name", claim).withIssuer(issuer).build();
DecodedJWT jwt = verifier.verify(token);
valid = true;
} catch (Exception e) {
throw new IllegalStateException(e.getLocalizedMessage());
}
return valid;
}
Aggregations