Java Code Examples for io.jsonwebtoken.Claims#setIssuedAt()
The following examples show how to use
io.jsonwebtoken.Claims#setIssuedAt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenHelper.java From springboot-jwt-starter with MIT License | 6 votes |
public String refreshToken(String token, Device device) { String refreshedToken; Date a = timeProvider.now(); try { final Claims claims = this.getAllClaimsFromToken(token); claims.setIssuedAt(a); refreshedToken = Jwts.builder() .setClaims(claims) .setExpiration(generateExpirationDate(device)) .signWith( SIGNATURE_ALGORITHM, SECRET ) .compact(); } catch (Exception e) { refreshedToken = null; } return refreshedToken; }
Example 2
Source File: JwtTokenUtil.java From spring-boot-vuejs-fullstack-examples with MIT License | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); }
Example 3
Source File: JwtTokenUtil.java From pcf-crash-course-with-spring-boot with MIT License | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); }
Example 4
Source File: JwtTokenUtil.java From docker-crash-course with MIT License | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); }
Example 5
Source File: JwtTokenUtil.java From spring-react-boilerplate with MIT License | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret) .compact(); }
Example 6
Source File: JwtTokenUtil.java From webFluxTemplate with MIT License | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret) .compact(); }
Example 7
Source File: JwtTokenUtil.java From spring-security-mybatis-demo with Apache License 2.0 | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret) .compact(); }
Example 8
Source File: JwtTokenUtil.java From spring-boot-start-current with Apache License 2.0 | 5 votes |
public String refreshToken(String token) { final Date createdDate = clock.now(); final Date expirationDate = calculateExpirationDate(createdDate); final Claims claims = getAllClaimsFromToken(token); claims.setIssuedAt(createdDate); claims.setExpiration(expirationDate); return Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret) .compact(); }
Example 9
Source File: JwtTokenHelper.java From quartz-manager with Apache License 2.0 | 5 votes |
public String refreshToken(String token) { String refreshedToken; try { final Claims claims = getClaimsFromToken(token); claims.setIssuedAt(generateCurrentDate()); refreshedToken = generateToken(claims); } catch (Exception e) { log.error("Error refreshing jwt token due to " + e.getMessage(), e); refreshedToken = null; } return refreshedToken; }
Example 10
Source File: RefreshTokenGranter.java From oauth2-server with MIT License | 4 votes |
@Override public Map<String, Object> grant(OauthClient client, String grantType, Map<String, String> parameters) { Map<String, Object> result = new HashMap<>(); result.put("status", 0); String refreshToken = parameters.get("refresh_token"); if (!GRANT_TYPE.equals(grantType)) { return result; } try { Claims claims = Jwts.parserBuilder().setSigningKey(keyPair.getPublic()).build().parseClaimsJws(refreshToken).getBody(); Date now = new Date(); Date tokenExpiration = Date.from(LocalDateTime.now().plusSeconds(client.getAccessTokenValidity()).atZone(ZoneId.systemDefault()).toInstant()); Date refreshTokenExpiration = Date.from(LocalDateTime.now().plusSeconds(client.getRefreshTokenValidity()).atZone(ZoneId.systemDefault()).toInstant()); String tokenId = UUID.randomUUID().toString(); claims.setId(tokenId); claims.setIssuedAt(now); claims.setExpiration(tokenExpiration); claims.setNotBefore(now); claims.put("jti", tokenId); String newRefreshToken = Jwts.builder() .setHeaderParam("alg", "HS256") .setHeaderParam("typ", "JWT") .setClaims(claims) .signWith(keyPair.getPrivate()) .compact(); claims.setId(tokenId); claims.setIssuedAt(now); claims.setExpiration(tokenExpiration); claims.setNotBefore(now); claims.remove("jti"); String accessToken = Jwts.builder() .setHeaderParam("alg", "HS256") .setHeaderParam("typ", "JWT") .setClaims(claims) .signWith(keyPair.getPrivate()) .compact(); result.put("access_token", accessToken); result.put("token_type", "bearer"); result.put("refresh_token", newRefreshToken); result.put("expires_in", client.getAccessTokenValidity() - 1); result.put("accountOpenCode", claims.get("accountOpenCode")); result.put("scope", "user_info"); result.put("jti", tokenId); result.put("status", 1); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("exception", e); } throw e; } return result; }
Example 11
Source File: JwtAuth.java From liberty-bikes with Eclipse Public License 1.0 | 4 votes |
/** * Obtain a JWT with the claims supplied. The key "id" will be used to set * the JWT subject. * * @param claims map of string->string for claim data to embed in the jwt. * @return jwt encoded as string, ready to send to http. */ protected String createJwt(Map<String, String> claims) throws IOException { if (signingKey == null) { getKeyStoreInfo(); } Claims onwardsClaims = Jwts.claims(); // Add all the remaining claims as-is. onwardsClaims.putAll(claims); // Set the subject using the "id" field from our claims map. onwardsClaims.setSubject(claims.get("id")); onwardsClaims.setId(claims.get("id")); // We'll use this claim to know this is a user token onwardsClaims.setAudience("client"); onwardsClaims.setIssuer("https://libertybikes.mybluemix.net"); // we set creation time to 24hrs ago, to avoid timezone issues in the // browser verification of the jwt. Calendar calendar1 = Calendar.getInstance(); calendar1.add(Calendar.HOUR, -24); onwardsClaims.setIssuedAt(calendar1.getTime()); // client JWT has 24 hrs validity from now. Calendar calendar2 = Calendar.getInstance(); calendar2.add(Calendar.HOUR, 24); onwardsClaims.setExpiration(calendar2.getTime()); // finally build the new jwt, using the claims we just built, signing it // with our signing key, and adding a key hint as kid to the encryption header, // which is optional, but can be used by the receivers of the jwt to know which // key they should verify it with. return Jwts.builder() .setHeaderParam("kid", "bike") .setHeaderParam("alg", "RS256") .setClaims(onwardsClaims) .signWith(SignatureAlgorithm.RS256, signingKey) .compact(); }