diff options
author | crupest <crupest@outlook.com> | 2021-05-16 20:17:55 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-05-16 20:17:55 +0800 |
commit | 230cffd2a4932fe6b46c5f0e787e6ef4a99ec3ef (patch) | |
tree | 4a54bfd3baa105292271b179b3e02deab0fe050c /BackEnd | |
parent | 07afe9dea19920a95391e5aa2f356264ee563916 (diff) | |
download | timeline-230cffd2a4932fe6b46c5f0e787e6ef4a99ec3ef.tar.gz timeline-230cffd2a4932fe6b46c5f0e787e6ef4a99ec3ef.tar.bz2 timeline-230cffd2a4932fe6b46c5f0e787e6ef4a99ec3ef.zip |
fix: Fix backend signalr auth.
Diffstat (limited to 'BackEnd')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs | 8 | ||||
-rw-r--r-- | BackEnd/Timeline/Auth/MyAuthenticationHandler.cs | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs index 05d4c28c..e8b774d8 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs @@ -17,8 +17,12 @@ namespace Timeline.Tests.IntegratedTests private HubConnection CreateConnection(string? token)
{
- return new HubConnectionBuilder().WithUrl($"http://localhost/api/hub/timeline{(token is null ? "" : "?token=" + token)}",
- options => options.HttpMessageHandlerFactory = _ => TestApp.Server.CreateHandler()).Build();
+ return new HubConnectionBuilder().WithUrl("http://localhost/api/hub/timeline",
+ options =>
+ {
+ options.HttpMessageHandlerFactory = _ => TestApp.Server.CreateHandler();
+ options.AccessTokenProvider = token is null ? null : () => Task.FromResult(token);
+ }).Build();
}
[Theory]
diff --git a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs index 949dd832..016cc938 100644 --- a/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs +++ b/BackEnd/Timeline/Auth/MyAuthenticationHandler.cs @@ -100,6 +100,17 @@ namespace Timeline.Auth }
}
+ {
+ var token = Request.Query["access_token"];
+ var path = Context.Request.Path;
+
+ if (!string.IsNullOrEmpty(token) && path.StartsWithSegments("/api/hub"))
+ {
+ _logger.LogInformation(Resource.LogTokenFoundInQuery, "access_token", token);
+ return token;
+ }
+ }
+
// not found anywhere then return null
return null;
}
|