From 230cffd2a4932fe6b46c5f0e787e6ef4a99ec3ef Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 16 May 2021 20:17:55 +0800 Subject: fix: Fix backend signalr auth. --- BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs | 8 ++++++-- BackEnd/Timeline/Auth/MyAuthenticationHandler.cs | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'BackEnd') 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; } -- cgit v1.2.3