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 long REFRESH_TOKEN_LIFETIME_MILLIS  
    static long TOKEN_LIFETIME_MILLIS  
  • Method Summary

    Modifier and Type Method Description
    static io.jsonwebtoken.Jwt decodeJwToken​(java.lang.String jwToken)
    Decodes a JWT token
    static java.lang.String getAccessToken​(java.lang.String id, java.lang.String user)
    Generates a short lived access token
    static java.lang.String getCustomToken​(java.lang.String id, java.lang.String user, long lifetime)
    Generates a custom token
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 id
      user - the token subject
      lifetime - 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 token
      user - 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 id
      user - 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 parser
      io.jsonwebtoken.SignatureException - if error with signature
      java.lang.IllegalArgumentException - if error parsing