Ejemplo n.º 1
0
 /// <summary>
 /// Generates a JSON Web Token using the specified parameters asynchronously.
 /// </summary>
 /// <param name="identity">The identity to encode.</param>
 /// <param name="userId">The user identifier for the token.</param>
 /// <param name="userName">The user name for the token.</param>
 /// <param name="role">The user role for the token.</param>
 /// <param name="factory">An object that generates the encoded token.</param>
 /// <param name="options">An object that indicates validity of the token.</param>
 /// <returns></returns>
 public static async Task <IJwtToken> GenerateJwtAsync(this ClaimsIdentity identity, string userId, string userName, string role, IJwtFactory factory, JwtIssuerOptions options)
 {
     return(new JwtToken
     {
         Id = userId,
         AuthToken = await factory.GenerateEncodedToken(userName, identity),
         ExpiresIn = (int)options.ValidFor.TotalSeconds,
         Role = role,
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JwtFactory"/> class using the specified parameter.
 /// </summary>
 /// <param name="jwtOptions">An object that provides access to an instance of the <see cref="JwtIssuerOptions"/> class.</param>
 public JwtFactory(IOptions <JwtIssuerOptions> jwtOptions)
 {
     _jwtOptions = jwtOptions.Value;
     ThrowIfInvalidOptions(_jwtOptions);
 }