Class TokensUtils
java.lang.Object
com.fredriksonsound.iot_backoffice_auth.util.TokensUtils
public class TokensUtils
extends java.lang.Object
Utility class for tokens
-
Field Summary
Fields Modifier and Type Field Description static longREFRESH_TOKEN_LIFETIME_MILLISstatic longTOKEN_LIFETIME_MILLIS -
Method Summary
Modifier and Type Method Description static io.jsonwebtoken.JwtdecodeJwToken(java.lang.String jwToken)Decodes a JWT tokenstatic java.lang.StringgetAccessToken(java.lang.String id, java.lang.String user)Generates a short lived access tokenstatic java.lang.StringgetCustomToken(java.lang.String id, java.lang.String user, long lifetime)Generates a custom tokenstatic java.lang.StringgetRefreshToken(java.lang.String id, java.lang.String user)Generates a long lived refresh token for a specified user, with a specified token id
-
Field Details
-
TOKEN_LIFETIME_MILLIS
public static final long TOKEN_LIFETIME_MILLIS- See Also:
- Constant Field Values
-
REFRESH_TOKEN_LIFETIME_MILLIS
public static final long REFRESH_TOKEN_LIFETIME_MILLIS- See Also:
- Constant Field Values
-
-
Method Details
-
getCustomToken
public static java.lang.String getCustomToken(java.lang.String id, java.lang.String user, long lifetime)Generates a custom token- Parameters:
id- the token iduser- the token subjectlifetime- the token lifetime- Returns:
- a new custom token
-
getAccessToken
public static java.lang.String getAccessToken(java.lang.String id, java.lang.String user)Generates a short lived access token- Parameters:
id- the id of the tokenuser- the user this token is valid for- Returns:
- a short lived JWT token
-
getRefreshToken
public static java.lang.String getRefreshToken(java.lang.String id, java.lang.String user)Generates a long lived refresh token for a specified user, with a specified token id- Parameters:
id- the token iduser- the user the token is valid for- Returns:
- a long lived refresh token
-
decodeJwToken
public static io.jsonwebtoken.Jwt decodeJwToken(java.lang.String jwToken)Decodes a JWT token- Parameters:
jwToken- the encoded token to decode- Returns:
- a decoded token body
- Throws:
io.jsonwebtoken.MalformedJwtException- if error occurs in parserio.jsonwebtoken.SignatureException- if error with signaturejava.lang.IllegalArgumentException- if error parsing
-