Search in sources :

Example 96 with Token

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);
}
Also used : LoginResultJson(emu.grasscutter.server.http.objects.LoginResultJson) Account(emu.grasscutter.game.Account) VerifyJson(com.xtaolabs.gcauth_oauth.json.VerifyJson) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 97 with Token

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();
}
Also used : JWTVerifier(com.auth0.jwt.JWTVerifier) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 98 with Token

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;
}
Also used : JWTVerifier(com.auth0.jwt.interfaces.JWTVerifier) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 99 with Token

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);
}
Also used : HashMap(java.util.HashMap) Algorithm(com.auth0.jwt.algorithms.Algorithm) Date(java.util.Date)

Example 100 with Token

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;
}
Also used : JWTCreator(com.auth0.jwt.JWTCreator) ToString(lombok.ToString) Date(java.util.Date)

Aggregations

DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)276 Algorithm (com.auth0.jwt.algorithms.Algorithm)147 Test (org.junit.Test)120 JWTVerifier (com.auth0.jwt.JWTVerifier)97 Date (java.util.Date)78 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)62 IOException (java.io.IOException)59 Claim (com.auth0.jwt.interfaces.Claim)49 HashMap (java.util.HashMap)40 VoidRequest (com.auth0.net.VoidRequest)31 RSAPublicKey (java.security.interfaces.RSAPublicKey)31 Test (org.junit.jupiter.api.Test)30 JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)28 JWTCreator (com.auth0.jwt.JWTCreator)21 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)21 JWT (com.auth0.jwt.JWT)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 Instant (java.time.Instant)18 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)17