Class JwtService

java.lang.Object
no.idata1002.group19.service.JwtService

@Component public class JwtService extends Object
Represents an JSON Web Token (JWT) service which generates JWT Tokens upon user authentication, and to validate JWTs provided by the client to ensure the credibility of the given requests.
Since:
16.04.2023
Version:
16.04.2023
Author:
Group19
  • Constructor Details

    • JwtService

      public JwtService()
  • Method Details

    • getToken

      public String getToken(String username)
      Generates a JWT Token with the given username and expiration time which are to be returned to the client upon authorization.
      Parameters:
      username - The username of the authenticated user.
      Returns:
      Generated JSON Web Token as a String.
    • getAuthUser

      public String getAuthUser(jakarta.servlet.http.HttpServletRequest request)
      Validates a JWT which a client has provided in its request header.
      Parameters:
      request - The HTTP request which the client forwarded to the server.
      Returns:
      String username of the user which the JWT was generated to.