// 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:44328")); options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("http://localhost:3000")); }); //Swagger döküman tanýmýný yapýyoruz. services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "WebApplication1", Version = "v1" }); }); var tokenOption = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidIssuer = tokenOption.Issuer, ValidateIssuerSigningKey = true, IssuerSigningKey = SecurityKeyHelper.CrSecurityKey(tokenOption.SecurityKey) }; }); }
public AccessToken CreateToken(Person user) { _accesTokenExpiration = DateTime.Now.AddMinutes(_tokenOptions.AccessTokenExpiration); var securityKey = SecurityKeyHelper.CrSecurityKey(_tokenOptions.SecurityKey); var signingCredentials = SigningCredentialHelper.CreateSigningCredentials(securityKey); var jwt = CrJwtSecurityToken(_tokenOptions, user, signingCredentials); var JwtSecurityTokenHandler = new JwtSecurityTokenHandler(); var token = JwtSecurityTokenHandler.WriteToken(jwt); return(new AccessToken() { Token = token, Expiration = _accesTokenExpiration }); }