Class AuthTokenService
- Namespace
- GastroSky.Services.AuthTokenService
- Assembly
- GastroSky.dll
public class AuthTokenService : IAuthTokenService
- Inheritance
-
AuthTokenService
- Implements
- Inherited Members
Constructors
AuthTokenService(GastroSkyDatabaseContext, ILogger<AuthTokenService>, IOptionsMonitor<JwtSettings>)
public AuthTokenService(GastroSkyDatabaseContext db, ILogger<AuthTokenService> logger, IOptionsMonitor<JwtSettings> settingsMonitor)
Parameters
dbGastroSkyDatabaseContextloggerILogger<AuthTokenService>settingsMonitorIOptionsMonitor<JwtSettings>
Methods
EmitAuthTokenForUserAccount(User)
Emits a new authentication token for a given userAccount.
public string EmitAuthTokenForUserAccount(User userAccount)
Parameters
Returns
- string
The token string ready for the user to append to his subsequent requests (inside the
AuthorizationHTTP header with theBearerprefix).
EmitDefibrillatorTokenForUserAccount(User)
Emits a new defibrillator token useful for reviving dead sessions (expired).
Defi-Tokens have a slightly longer lifetime, but need to be handled with the same (if not more) care as the normal auth tokens.
public string EmitDefibrillatorTokenForUserAccount(User userAccount)
Parameters
Returns
ExtractJwt(HttpContext)
Extracts the authorization header value from a request's HttpContext.
public string? ExtractJwt(HttpContext httpContext)
Parameters
httpContextHttpContextHTTP request's HttpContext to extract the token from.
Returns
- string
The found JWT (
nullif no auth token was found inside the request's authorization header).
ValidateReviveRequest(ReviveRequestDto)
Checks whether a defibrillator token that was emitted by the EmitDefibrillatorTokenForUserAccount(User) method is valid or not.
public string? ValidateReviveRequest(ReviveRequestDto dto)
Parameters
dtoReviveRequestDtoThe revival request DTO to check.
Returns
- string
nullif validation failed; thesubclaim value if validation was successful (which should correspond to the User's Slug value).
Remarks
This will NOT obliterate the token: do not forget to do that in case of validity and renewal!