Sources/Api/Startup.cs
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services">services collection</param>
This method gets called by the runtime. Use this method to add services to the container.
This method gets called by the runtime . Use this method to add services to the container .
public void ConfigureServices(IServiceCollection services)
        {
            IConfigurationSection identitySection = Configuration.GetSection("Identity");
            IdentityConfiguration identityConfiguration = identitySection.Get<IdentityConfiguration>();
            byte[] key = Encoding.UTF8.GetBytes(identityConfiguration.JwtTokenSymmetricKey);
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata = true;
                x.SaveToken = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(key),
                    ValidateIssuer = false,
                    ValidateAudience = false
                };
            });
            services.AddLocalization();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddCors();
            services.Configure<IdentityConfiguration>(identitySection);
            services.AddIdentity<User, Role>()
                .AddErrorDescriber<MultilanguageIdentityErrorDescriber>();
            services.AddSingleton<IRoleStore<Role>, RolesRepository>();
            services.AddSingleton<IUserStore<User>, UsersRepository>();
            services.AddSingleton<IIdentityService, IdentityService>();
        }
public void ConfigureServices ( IServiceCollection services ) { IConfigurationSection identitySection = Configuration . GetSection ( " " ) ; IdentityConfiguration identityConfiguration = identitySection . Get < IdentityConfiguration > ( ) ; byte [ ] key = Encoding . UTF8 . GetBytes ( identityConfiguration . JwtTokenSymmetricKey ) ; services . AddAuthentication ( x => { x . DefaultAuthenticateScheme = JwtBearerDefaults . AuthenticationScheme ; x . DefaultChallengeScheme = JwtBearerDefaults . AuthenticationScheme ; } ) . AddJwtBearer ( x => { x . RequireHttpsMetadata = true ; x . SaveToken = true ; x . TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true , IssuerSigningKey = new SymmetricSecurityKey ( key ) , ValidateIssuer = false , ValidateAudience = false } ; } ) ; services . AddLocalization ( ) ; services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ; services . AddCors ( ) ; services . Configure < IdentityConfiguration > ( identitySection ) ; services . AddIdentity < User , Role > ( ) . AddErrorDescriber < MultilanguageIdentityErrorDescriber > ( ) ; services . AddSingleton < IRoleStore < Role > , RolesRepository > ( ) ; services . AddSingleton < IUserStore < User > , UsersRepository > ( ) ; services . AddSingleton < IIdentityService , IdentityService > ( ) ; }
This method gets called by the runtime.
This method gets called by the runtime .
// configure jwt authentication
services
IServiceCollection
None