// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAutoMapper(); services.AddCors(); services.AddScoped <IUnitOfWork, UnitOfWork>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IRelationService, RelationService>(); services.AddScoped <IRelationRepository, RelationRepository>(); services.AddScoped <IMeetingService, MeetingService>(); services.AddScoped <IMeetingRepository, MeetingRepository>(); services.AddScoped <JwtTokenFactory>(); services.AddScoped <IAuthService, AuthService>(); var builder = services.AddIdentityCore <User>(opt => { opt.Password.RequiredLength = 3; opt.Password.RequireLowercase = false; opt.Password.RequireUppercase = false; opt.Password.RequireDigit = false; opt.Password.RequireNonAlphanumeric = false; }); builder = new IdentityBuilder(builder.UserType, typeof(UserRole), builder.Services); builder.AddEntityFrameworkStores <ApplicationDbContext>(); builder.AddSignInManager <SignInManager <User> >(); services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration.GetSection("JwtTokens")["Issuer"], ValidAudience = Configuration.GetSection("JwtTokens")["Audience"], IssuerSigningKey = JwtTokenFactory.GetSecurityKey(Configuration.GetSection("JwtTokens")["Key"]) }; }); services.AddDbContext <ApplicationDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("LocalDb"), b => b.MigrationsAssembly("Geoloc")); }); }
public void GetSecurityKey_GivenTheSameKeys_ReturnsIdenticalSecurityKeyId() { // Arrange const string key = "test_key"; // Act var result1 = JwtTokenFactory.GetSecurityKey(key); var result2 = JwtTokenFactory.GetSecurityKey(key); // Assert Assert.AreEqual(result1.KeyId, result2.KeyId); }