Fix JWTUtils class
This commit is contained in:
parent
239850a2fc
commit
d3572ee92c
2 changed files with 10 additions and 4 deletions
|
|
@ -2,7 +2,10 @@ package br.com.rayankonecny.authserviceapi.utils;
|
||||||
|
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
import io.jsonwebtoken.security.Keys;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.Key;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
@ -20,13 +23,16 @@ public class JWTUtils {
|
||||||
private Long expiration;
|
private Long expiration;
|
||||||
|
|
||||||
public String generateToken(final UserDetailsDTO user) {
|
public String generateToken(final UserDetailsDTO user) {
|
||||||
|
|
||||||
|
Key key = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.claim("id", user.getId())
|
.claim("id", user.getId())
|
||||||
.claim("name", user.getName())
|
.claim("name", user.getName())
|
||||||
.claim("authorities", user.getAuthorities())
|
.claim("authorities", user.getAuthorities())
|
||||||
.setSubject(user.getUsername())
|
.subject(user.getUsername())
|
||||||
.signWith(SignatureAlgorithm.HS512, secret.getBytes())
|
.expiration(new Date(System.currentTimeMillis()+ expiration))
|
||||||
.setExpiration(new Date(System.currentTimeMillis()+ expiration))
|
.signWith(key)
|
||||||
.compact();
|
.compact();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,4 @@ spring:
|
||||||
enabled: false
|
enabled: false
|
||||||
jwt.secret: "IHf3Yua/byvtA+iIcGWmkrLvpKEXTb5ClkXaZ0VDmYbr/6b1otCs38x68bidvZLAOB7anUtVQlCid6YDULO5XA=="
|
jwt.secret: "IHf3Yua/byvtA+iIcGWmkrLvpKEXTb5ClkXaZ0VDmYbr/6b1otCs38x68bidvZLAOB7anUtVQlCid6YDULO5XA=="
|
||||||
jwt.expiration: 120000
|
jwt.expiration: 120000
|
||||||
jwt.expiration-sec.refresh-token: 5
|
jwt.expiration-sec.refresh-token: 3600
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue