public JwtFactoryTests() { var fixture = new Fixture(); var signingKey = new SymmetricSecurityKey(Encoding.Default.GetBytes(fixture.Create <string>())); _jwtConfiguration = fixture .Build <JwtConfiguration>() .With(config => config.SigningCredentials, new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256)) .Create(); var configuration = Options.Create(_jwtConfiguration); _jwtFactory = new JwtFactory(configuration); }
private static void ThrowIfInvalidOptions(JwtConfiguration options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.ValidFor <= TimeSpan.Zero) { throw new ArgumentException("Must be a non-zero TimeSpan."); } if (options.SigningCredentials == null) { throw new ArgumentException(nameof(JwtConfiguration.SigningCredentials)); } if (options.JtiGenerator == null) { throw new ArgumentException(nameof(JwtConfiguration.JtiGenerator)); } }
public JwtFactory(IOptions <JwtConfiguration> jwtOptions) { _jwtConfiguration = jwtOptions.Value; ThrowIfInvalidOptions(_jwtConfiguration); }