示例#1
0
        public static IServiceCollection AddJwtAuthentication(this IServiceCollection services, Action <JwtAuthenticationOptionsExtension> jwtOptionsExtension)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            _jwtOptionsExtension = new JwtAuthenticationOptionsExtension();
            jwtOptionsExtension(_jwtOptionsExtension);

            services.AddSingleton(new JwtTokenProvider(_jwtOptionsExtension));

            var authenticationBuilder = services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            });

            authenticationBuilder.AddJwtBearer(JwtBearerOptionAction);

            return(services);
        }
示例#2
0
 public JwtTokenProvider(JwtAuthenticationOptionsExtension jwtOptionsExtension)
 {
     _jwtOptionsExtension = jwtOptionsExtension;
 }