public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, Action <JwtSecurityOptions> configureOptions)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var jwtSecurityOptions = new JwtSecurityOptions();

            configureOptions(jwtSecurityOptions);

            var tokenHandler = new TokenHandler(jwtSecurityOptions);

            services.AddAuthentication(
                options => {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = tokenHandler.TokenValidationParameters;
            });

            return(services);
        }
コード例 #2
0
        public TokenHandler(JwtSecurityOptions options)
        {
            this.options = options ?? throw new ArgumentNullException(nameof(options));

            this.symmetricSecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(options.IssuerSigningKey));
        }
コード例 #3
0
 public MachineKeyCompatibilityDataFormat(JwtSecurityOptions jwtSecurityOptions)
     : this(new TokenHandler(jwtSecurityOptions))
 {
 }
コード例 #4
0
 public JwtSecureDataFormat(JwtSecurityOptions jwtSecurityOptions)
     : this(new TokenHandler(jwtSecurityOptions))
 {
 }