Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
 public JwtFactory(IOptions <JwtConfiguration> jwtOptions)
 {
     _jwtConfiguration = jwtOptions.Value;
     ThrowIfInvalidOptions(_jwtConfiguration);
 }