Example #1
0
        public static IServiceCollection AddSlothAuthentication(this IServiceCollection services, IConfiguration configuration)
        {
            var authoptions = new SlothAuthenticationOptions();

            configuration.Bind("AuthenticationConfig", authoptions);
            services.Configure <SlothAuthenticationOptions>(configuration.GetSection("AuthenticationConfig"));
            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })

            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = authoptions.TokenValidationParameters;
            });

            services.AddTransient <IPasswordHasher <User>, PasswordHasher <User> >();
            services.AddTransient <IAuthProvider, NativeAuthProvider>();
            services.AddTransient <IAuthService, AuthService>();
            services.AddTransient <ITokenProvider, JwtTokenProvider>();
            return(services);
        }
Example #2
0
 public JwtTokenProvider(IOptions <SlothAuthenticationOptions> authenticationOptions)
 {
     _authenticationOptions = authenticationOptions.Value;
 }