// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:4000")); }); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOptions.Audience, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CreateKeyHelper(tokenOptions.SecurityKey) }; }); //services.AddSingleton<IBrandService, BrandManager>(); //services.AddSingleton<IBrandDal, EFBrandDal>(); //services.AddSingleton<ICarService, CarManager>(); //services.AddSingleton<ICarDal, EFCarDal>(); //services.AddSingleton<IColorService,ColorManager>(); //services.AddSingleton<IColorDal, EFColorDal>(); //services.AddSingleton<IRentalService, RentalManager>(); //services.AddSingleton<IRentalDal, EfRentalDal>(); //services.AddSingleton<IUserService, UserManager>(); //services.AddSingleton<IUserDal, EfUserDal>(); }
public AccessToken CreateToken(User user, List <OperationClaim> operationClaims) { var securityKey = SecurityKeyHelper.CreateKeyHelper(_tokenOptions.SecurityKey); var signingCredantials = SigningCredantialHelper.CreateSigningCredentials(securityKey); var jwt = CreateJwtSecurityToken(_tokenOptions, user, signingCredantials, operationClaims); var JwtSecurityTokenHandler = new JwtSecurityTokenHandler(); var token = JwtSecurityTokenHandler.WriteToken(jwt); return(new AccessToken() { Token = token, Expiration = _accessTokenExpiration }); }