From 6775edfd66f300dc6ee5b4044f0b7c31c6429db4 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Wed, 29 Jan 2025 16:02:55 -0500 Subject: [PATCH] fix logic to retrieve access token --- Oqtane.Server/Components/App.razor | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Oqtane.Server/Components/App.razor b/Oqtane.Server/Components/App.razor index 9b17e701..712f7145 100644 --- a/Oqtane.Server/Components/App.razor +++ b/Oqtane.Server/Components/App.razor @@ -7,6 +7,7 @@ @using Microsoft.AspNetCore.Localization @using Microsoft.Net.Http.Headers @using Microsoft.Extensions.Primitives +@using Microsoft.AspNetCore.Authentication @using Oqtane.Client @using Oqtane.UI @using Oqtane.Repository @@ -177,7 +178,7 @@ // get jwt token for downstream APIs if (Context.User.Identity.IsAuthenticated) { - GetJwtToken(alias); + await GetJwtToken(alias); } // includes resources @@ -444,15 +445,11 @@ } } - private void GetJwtToken(Alias alias) + private async Task GetJwtToken(Alias alias) { - _authorizationToken = Context.Request.Headers[HeaderNames.Authorization]; - if (!string.IsNullOrEmpty(_authorizationToken)) - { - // bearer token was provided by remote Identity Provider and was persisted using SaveTokens - _authorizationToken = _authorizationToken.Replace("Bearer ", ""); - } - else + // bearer token may have been provided by remote Identity Provider and persisted using SaveTokens = true + _authorizationToken = await Context.GetTokenAsync("access_token"); + if (string.IsNullOrEmpty(_authorizationToken)) { // generate bearer token if a secret has been configured in User Settings var sitesettings = Context.GetSiteSettings();