aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-05-06 21:24:29 +0800
committercrupest <crupest@outlook.com>2019-05-06 21:24:29 +0800
commit050a2957a325b337b53b91ca3fa494b66950a6d9 (patch)
treeb18f8f7e4d8dbfa8cfe57e97fe5fe9a84a9a6de8
parent79dc38059819cf6dbcb8533b031f9a0dba8f6cb1 (diff)
downloadtimeline-050a2957a325b337b53b91ca3fa494b66950a6d9.tar.gz
timeline-050a2957a325b337b53b91ca3fa494b66950a6d9.tar.bz2
timeline-050a2957a325b337b53b91ca3fa494b66950a6d9.zip
You can use "token" query param to auth now.
-rw-r--r--Timeline/Startup.cs15
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;