use of com.auth0.json.mgmt.Token in project GCAuth-OAuth by Xtao-Team.
the class VerifyHandler method handle.
public static void handle(Request req, Response res) {
VerifyJson request = req.body(VerifyJson.class);
LoginResultJson responseData = new LoginResultJson();
DecodedJWT jwt = parse.deToken(request.access_token);
Account account = null;
if (jwt != null) {
account = Authentication.getAccountByOneTimeToken(jwt.getClaim("token").asString());
}
// Login
if (account == null) {
Grasscutter.getLogger().info("[GCAuth] Client " + req.ip() + " failed to log in");
responseData.retcode = -201;
responseData.message = "Token is invalid";
res.send(responseData);
return;
}
// Account was found, log the player in
responseData.message = "OK";
responseData.data.account.uid = account.getId();
responseData.data.account.token = account.generateSessionKey();
responseData.data.account.email = account.getEmail();
responseData.data.account.twitter_name = account.getUsername();
Grasscutter.getLogger().info(String.format("[GCAuth] Client %s logged in as %s", req.ip(), responseData.data.account.uid));
res.send(responseData);
}
use of com.auth0.json.mgmt.Token in project sports_hub_portal by Anastasiia-Rokytska.
the class JwtTokenService method verifyToken.
public String verifyToken(String token) {
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT decodedJWT = verifier.verify(token);
return decodedJWT.getSubject();
}
use of com.auth0.json.mgmt.Token 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.json.mgmt.Token in project bitrxc-server by bitrxc.
the class TokenManager method createTokenForAdmin.
// 管理员端token生成
public String createTokenForAdmin(String phone) {
Date expirationTime = new Date(System.currentTimeMillis() + this.tokenExpiration);
// 私钥及加密算法
Algorithm algorithm = Algorithm.HMAC256(tokenSignKey);
// 设置头信息
Map<String, Object> header = new HashMap<>();
header.put("typ", "JWT");
header.put("alg", "HS256");
return JWT.create().withHeader(header).withExpiresAt(expirationTime).withClaim("phone", phone).sign(algorithm);
}
use of com.auth0.json.mgmt.Token in project tutorials by jhkim105.
the class AuthenticationTokenUtil method generateToken.
public String generateToken(AuthUser authUser) {
Date now = new Date();
JWTCreator.Builder builder = JWT.create().withClaim(CLAIM_USER_ID, authUser.getUserId()).withClaim(CLAIM_USERNAME, authUser.getUsername()).withClaim(CLAIM_SCOPES, authUser.getScopes()).withIssuedAt(now);
if (this.expiry != 0)
builder.withExpiresAt(DateUtils.addSeconds(now, expiry));
String token = builder.sign(algorithm);
log.debug("token:{}", token);
return token;
}
Aggregations