protected TokenInfo createTokenInfo(Map<String, Object> map) { SimpleTokenInfo info = new SimpleTokenInfo(); info.setClientId((String)map.get("client_id")); info.setUserId((String)map.get("user_id")); info.setCreated(System.currentTimeMillis()); info.setExpiresIn(((Integer)map.get("expires_in"))); info.setScope((String)map.get("scope")); info.setClaims(map); return info; } }
protected TokenInfo doVerifyToken(Token token) { try { Map<String, Object> claims = server.verifyToken(token.getToken()); String clientId = (String)claims.get(JWT.CLAIM_AUDIENCE); OAuth2Client client = server.getClient(clientId); SimpleTokenInfo tokenInfo = new SimpleTokenInfo(); tokenInfo.setClientId(clientId); tokenInfo.setCreated(System.currentTimeMillis()); tokenInfo.setScope(client.getScope()); Object exp = claims.get(JWT.CLAIM_EXPIRATION_TIME); if (null != exp && exp instanceof Number) { long expirationTimeSecond = ((Number) exp).longValue(); long nowTimeInSecond = System.currentTimeMillis()/1000L; tokenInfo.setExpiresIn((int)(expirationTimeSecond-nowTimeInSecond)); } return tokenInfo; }catch (TokenVerifyException e) { if(isInternalOnly()) { throw e; } return null; } }
protected TokenInfo verify(JwtVerifier verifier, String token) throws TokenVerifyException { Map<String,Object> jwtDetail; try { jwtDetail = verifier.verify(token); }catch (TokenVerifyException e) { refreshJwtVerifier(); jwtDetail = verifier.verify(token); } SimpleTokenInfo tokenInfo = new SimpleTokenInfo(); String userId = (String)jwtDetail.get(JWT.CLAIM_SUBJECT); tokenInfo.setUserId(userId); tokenInfo.setScope((String)jwtDetail.get("scope")); tokenInfo.setClientId((String)jwtDetail.get("client_id")); tokenInfo.setCreated(System.currentTimeMillis()); Object exp = jwtDetail.get(JWT.CLAIM_EXPIRATION_TIME); if (null != exp && exp instanceof Number) { long expirationTimeSecond = ((Number) exp).longValue(); long nowTimeInSecond = System.currentTimeMillis()/1000L; tokenInfo.setExpiresIn((int)(expirationTimeSecond-nowTimeInSecond)); } tokenInfo.setClaims(jwtDetail); return tokenInfo; }