diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-17 16:31:11 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-10-17 16:31:11 +0800 |
commit | 297d0c9029360f1d5334ed843b9b299356740ec1 (patch) | |
tree | c879e5d5e9a67c03e87b9d6ad067112d1ae2b118 | |
parent | 6875d8f1b2f788d5ed87cdd044742bd0160229dd (diff) | |
parent | 6c5bc336e57b08ca2c84bb49fe1ad488cf91dc20 (diff) | |
download | timeline-297d0c9029360f1d5334ed843b9b299356740ec1.tar.gz timeline-297d0c9029360f1d5334ed843b9b299356740ec1.tar.bz2 timeline-297d0c9029360f1d5334ed843b9b299356740ec1.zip |
Merge remote-tracking branch 'origin/master'
-rw-r--r-- | Timeline/Startup.cs | 14 | ||||
-rw-r--r-- | Timeline/appsettings.json | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 7552df2e..8e8a6393 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.EntityFrameworkCore;
@@ -34,10 +35,19 @@ namespace Timeline services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
-
services.AddAuthentication(AuthConstants.Scheme)
.AddScheme<AuthOptions, AuthHandler>(AuthConstants.Scheme, AuthConstants.DisplayName, o => { });
+ var corsConfig = Configuration.GetSection("Cors").Get<string[]>();
+ services.AddCors(setup =>
+ {
+ setup.AddDefaultPolicy(new CorsPolicyBuilder()
+ .AllowAnyHeader()
+ .AllowAnyMethod()
+ .WithOrigins(corsConfig).Build()
+ );
+ });
+
services.AddScoped<IUserService, UserService>();
services.AddScoped<IJwtService, JwtService>();
services.AddTransient<IPasswordService, PasswordService>();
@@ -68,6 +78,8 @@ namespace Timeline app.UseRouting();
+ app.UseCors();
+
app.UseAuthentication();
app.UseAuthorization();
diff --git a/Timeline/appsettings.json b/Timeline/appsettings.json index 2d0f2b9f..61491ff5 100644 --- a/Timeline/appsettings.json +++ b/Timeline/appsettings.json @@ -7,5 +7,6 @@ "JwtConfig": {
"Issuer": "api.crupest.xyz",
"Audience": "api.crupest.xyz"
- }
+ },
+ "Cors": [ "https://www.crupest.xyz", "https://crupest.xyz" ]
}
|