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 | 3c17e25fb9eef49807f3c57104603bad355da005 (patch) | |
tree | b18f8f7e4d8dbfa8cfe57e97fe5fe9a84a9a6de8 | |
parent | 79dc38059819cf6dbcb8533b031f9a0dba8f6cb1 (diff) | |
parent | 050a2957a325b337b53b91ca3fa494b66950a6d9 (diff) | |
download | timeline-3c17e25fb9eef49807f3c57104603bad355da005.tar.gz timeline-3c17e25fb9eef49807f3c57104603bad355da005.tar.bz2 timeline-3c17e25fb9eef49807f3c57104603bad355da005.zip |
Merge pull request #23 from crupest/auth
You can use "token" query param to auth now.
-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; |