use of com.auth0.jwt.JWTVerifier in project micro-service-examples by jetlinks.
the class JwtAuthSupplier method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
if (StringUtils.isEmpty(token) || !token.startsWith("jwt")) {
return true;
}
JWTVerifier verifier = jwt.createVerifier();
DecodedJWT jwt = verifier.verify(token.substring(4));
ContextUtils.currentContext().put(Authentication.class, factory.create().json(jwt.getSubject()).build());
return true;
}
use of com.auth0.jwt.JWTVerifier in project kin-rsocket-broker by huangjianqin.
the class JwtAuthenticationService method auth.
@Override
public RSocketAppPrincipal auth(String credentials) {
if (Objects.isNull(credentials) || credentials.isEmpty()) {
return null;
}
// bearer jwt_token
credentials = credentials.substring(credentials.lastIndexOf(" ") + 1);
int tokenHashCode = credentials.hashCode();
RSocketAppPrincipal principal = jwtVerifyCache.getIfPresent(tokenHashCode);
for (JWTVerifier verifier : verifiers) {
try {
principal = new JwtPrincipal(verifier.verify(credentials));
jwtVerifyCache.put(tokenHashCode, principal);
break;
} catch (JWTVerificationException ignore) {
// do nothing
}
}
return principal;
}
use of com.auth0.jwt.JWTVerifier in project study by bage2014.
the class JWTTest method main.
public static void main(String[] args) throws IllegalArgumentException, UnsupportedEncodingException {
// jjwt();
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
try {
Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret");
// Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret".getBytes("UTF-8"));
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT jwt = verifier.verify(token);
System.out.println(jwt);
} catch (JWTVerificationException exception) {
// Invalid signature/claims
exception.printStackTrace();
}
}
use of com.auth0.jwt.JWTVerifier in project doorkeeper by limbo-world.
the class JwtTest method testOther.
@Test(expected = SignatureVerificationException.class)
public void testOther() {
String token = JWT.create().withExpiresAt(// 设置过期时间
DateUtils.addHours(new Date(), 1)).withSubject("sss").withAudience(// 设置接受方信息,一般时登录用户
"user1").sign(Algorithm.HMAC256("2222"));
String userId = JWT.decode(token).getAudience().get(0);
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("111111")).build();
DecodedJWT verify = jwtVerifier.verify(token);
System.out.println(JacksonUtil.toJSONString(verify));
}
use of com.auth0.jwt.JWTVerifier in project doorkeeper by limbo-world.
the class JWTUtil method verifyToken.
public static boolean verifyToken(String token, String secret) {
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(secret)).build();
jwtVerifier.verify(token);
return true;
}
Aggregations