public UnitTest_UpdatePassword_UserService() { db = new BlogApplicationDbContext(); var configuration = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new UserProfile()); cfg.AddProfile(new TokenProfile()); }); userService = new UserService(db, new AutoMapper.Mapper(configuration)); var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("blogapp!api!this_is@my@secret_key!")); tokenProviderOption = new TokenProviderOption { Audience = "ConsumerUser", Issuer = "BackEnd", SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.DefaultModelsExpandDepth(-1); c.DefaultModelExpandDepth(-1); c.SwaggerEndpoint("/swagger/v1/swagger.json", "Blog Application V1"); c.RoutePrefix = ""; c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.List); }); signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Keys:UserAuthSecretKey"])); userTokenOption = new TokenProviderOption { Audience = "ConsumerUser", Issuer = "BackEnd", SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; tokenValidationParameters = new TokenValidationParameters { // The signing key must match! ValidateIssuerSigningKey = true, IssuerSigningKey = signingKey, // Validate the JWT Issuer (iss) claim ValidateIssuer = true, ValidIssuer = "BackEnd", // Validate the JWT Audience (aud) claim ValidateAudience = true, ValidAudience = "ConsumerUser", // Validate the token expiry ValidateLifetime = true, // If you want to allow a certain amount of clock drift, set that here: ClockSkew = TimeSpan.Zero }; app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseCors("BlogReactClient_HTTPS"); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.ApplicationServices.CreateScope().ServiceProvider.GetService <BlogApplicationDbContext>().Database.Migrate(); }