Skip to content

Commit 8609484

Browse files
committed
feat: allow overwrite of token, so that it can be used during authentication
1 parent 5677f83 commit 8609484

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Catglobe.CgScript.Runtime/CgScriptAuthHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
2929
var httpContext = httpContextAccessor.HttpContext ??
3030
throw new InvalidOperationException("No HttpContext available from the IHttpContextAccessor!");
3131

32-
if (httpContext.User.Identity?.IsAuthenticated == true)
32+
string? accessToken = null;
33+
if ((httpContext.Items.TryGetValue("access_token", out var accessTokenObj) && accessTokenObj is string accessToken2)) accessToken = accessToken2;
34+
if (!string.IsNullOrEmpty(accessToken) || httpContext.User.Identity?.IsAuthenticated == true)
3335
{
34-
var accessToken = await httpContext.GetTokenAsync("access_token") ??
35-
throw new InvalidOperationException("No access_token was saved");
36+
accessToken ??= await httpContext.GetTokenAsync("access_token") ??
37+
throw new InvalidOperationException("No access_token was saved");
3638

3739
request.Headers.Authorization = new("Bearer", accessToken);
3840
}

0 commit comments

Comments
 (0)