diff options
author | 杨宇千 <crupest@outlook.com> | 2019-05-08 18:46:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-08 18:46:50 +0800 |
commit | 074e3cb2064c4d3e78e88e63e5f829070ed24967 (patch) | |
tree | b18f8f7e4d8dbfa8cfe57e97fe5fe9a84a9a6de8 /Timeline/Startup.cs | |
parent | ea84a067eee6dcd10dd0bc89967ef608677ef37e (diff) | |
parent | 056eec781bdb7064a409eb558a62edef6da2fc6d (diff) | |
download | timeline-074e3cb2064c4d3e78e88e63e5f829070ed24967.tar.gz timeline-074e3cb2064c4d3e78e88e63e5f829070ed24967.tar.bz2 timeline-074e3cb2064c4d3e78e88e63e5f829070ed24967.zip |
Merge pull request #23 from crupest/auth
You can use "token" query param to auth now.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r-- | Timeline/Startup.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 46d0afe5..acabe55c 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; using System.Text; +using System.Threading.Tasks; using Timeline.Configs; using Timeline.Formatters; using Timeline.Models; @@ -44,7 +45,7 @@ namespace Timeline if (Environment.IsProduction()) builder.WithOrigins("https://www.crupest.xyz", "https://crupest.xyz").AllowAnyMethod().AllowAnyHeader().AllowCredentials(); else - builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); + builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); @@ -54,6 +55,18 @@ namespace Timeline services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(o => { + o.Events = new JwtBearerEvents + { + OnMessageReceived = delegate (MessageReceivedContext context) + { + context.Request.Query.TryGetValue("token", out var value); + if (value.Count == 1) + { + context.Token = value[0]; + } + return Task.CompletedTask; + } + }; o.TokenValidationParameters.ValidateIssuer = true; o.TokenValidationParameters.ValidateAudience = true; o.TokenValidationParameters.ValidateIssuerSigningKey = true; |