Owneat Technical Guide main Help

Class JwtHelper

Namespace: Identity.API.Utils
Assembly: Identity.API.dll

JWT class that define methods for JWT generation and management.

public class JwtHelper : IJwtHelper

Inheritance

object ← JwtHelper

Implements

IJwtHelper

Inherited Members

object.Equals\(object?\), object.Equals\(object?, object?\), object.GetHashCode\(\), object.GetType\(\), object.MemberwiseClone\(\), object.ReferenceEquals\(object?, object?\), object.ToString\(\)

Constructors

JwtHelper\(IOptions<Jwt\>, IConfiguration\)

Class that define all method to manipulate and generate jwt tokens.

public JwtHelper(IOptions<Jwt> jwtSettingsOptions, IConfiguration configuration)

Parameters

jwtSettingsOptions IOptions < Jwt \>

  • Jwt options stored on appsettings file and injection via Options pattern.

configuration IConfiguration

Configuration of the project builder.

Methods

GenerateJwt\(IEnumerable<Claim\>\)

Method that generate a jwt.

public string GenerateJwt(IEnumerable<Claim> claims)

Parameters

claims IEnumerable < Claim \>

Claims to be encoded in the jwt.

Returns

string

The jwt token.

GenerateJwtFromUser\(User\)

Method that generates a jwt from a Identity.Domain.Aggregates.UserAggregate.User.

public string GenerateJwtFromUser(User user)

Parameters

user User

The user that the jwt is generated from.

Returns

string

The jwt response to return.

GenerateRefreshToken\(\)

Method to generate a refresh token for an expired token.

public string GenerateRefreshToken()

Returns

string

The refresh token.

GetPrincipalFromExpiredToken\(string\)

Get the principal claims from an expired token.

public ClaimsPrincipal GetPrincipalFromExpiredToken(string token)

Parameters

token string

The expired token.

Returns

ClaimsPrincipal

The System.Security.Claims.ClaimsPrincipal of the token.

Exceptions

SecurityTokenException

Exception thrown if the security algorithm used do not match the Microsoft.IdentityModel.Tokens.SecurityAlgorithms.

Last modified: 21 May 2024