From f41b6e5ec431c88bc1d94e4832d8ba49ddc42004 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Tue, 5 Mar 2024 11:19:52 +0100 Subject: HomeserverEmulator work --- Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs') diff --git a/Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs b/Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs index 8115bee..1f59342 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Services/TokenService.cs @@ -1,9 +1,7 @@ namespace LibMatrix.HomeserverEmulator.Services; -public class TokenService(IHttpContextAccessor accessor) { - public string? GetAccessToken() { - var ctx = accessor.HttpContext; - if (ctx is null) return null; +public class TokenService{ + public string? GetAccessToken(HttpContext ctx) { //qry if (ctx.Request.Query.TryGetValue("access_token", out var token)) { return token; @@ -11,16 +9,14 @@ public class TokenService(IHttpContextAccessor accessor) { //header if (ctx.Request.Headers.TryGetValue("Authorization", out var auth)) { var parts = auth.ToString().Split(' '); - if (parts.Length == 2 && parts[0] == "Bearer") { + if (parts is ["Bearer", _]) { return parts[1]; } } return null; } - public string? GenerateServerName() { - var ctx = accessor.HttpContext; - if (ctx is null) return null; + public string? GenerateServerName(HttpContext ctx) { return ctx.Request.Host.ToString(); } } \ No newline at end of file -- cgit 1.5.1