コード例 #1
0
        public static AuthenticationBuilder AddJwtBearerAuthentication(this IServiceCollection services, Action <JwtTokenOptions> options)
        {
            var optInstance = new JwtTokenOptions();

            options(optInstance);

            services.AddSingleton(optInstance);
            services.AddTransient <IJwtTokenService, JwtTokenService>();

            return(services.AddAuthentication(o =>
            {
                o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                o.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(cfg =>
            {
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateAudience = optInstance.ValidateAudience,
                    ValidateIssuer = optInstance.ValidateIssuer,
                    ValidateIssuerSigningKey = optInstance.ValidateIssuerSigningKey,
                    ValidateLifetime = optInstance.ValidateLifeTime,
                    IssuerSigningKey = optInstance.SecurityKey
                };
            }));
        }
コード例 #2
0
ファイル: JwtTokenService.cs プロジェクト: honam867/Agrifood
 public JwtTokenService(JwtTokenOptions options)
 {
     _options = options;
 }