Package no.idata1002.group19.service
Class JwtService
java.lang.Object
no.idata1002.group19.service.JwtService
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetAuthUser
(jakarta.servlet.http.HttpServletRequest request) Validates a JWT which a client has provided in its request header.Generates a JWT Token with the given username and expiration time which are to be returned to the client upon authorization.
-
Constructor Details
-
JwtService
public JwtService()
-
-
Method Details
-
getToken
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
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.
-