fix logic to retrieve access token

This commit is contained in:
sbwalker 2025-01-29 16:02:55 -05:00
parent 57879c1891
commit 6775edfd66

View File

@ -7,6 +7,7 @@
@using Microsoft.AspNetCore.Localization @using Microsoft.AspNetCore.Localization
@using Microsoft.Net.Http.Headers @using Microsoft.Net.Http.Headers
@using Microsoft.Extensions.Primitives @using Microsoft.Extensions.Primitives
@using Microsoft.AspNetCore.Authentication
@using Oqtane.Client @using Oqtane.Client
@using Oqtane.UI @using Oqtane.UI
@using Oqtane.Repository @using Oqtane.Repository
@ -177,7 +178,7 @@
// get jwt token for downstream APIs // get jwt token for downstream APIs
if (Context.User.Identity.IsAuthenticated) if (Context.User.Identity.IsAuthenticated)
{ {
GetJwtToken(alias); await GetJwtToken(alias);
} }
// includes resources // includes resources
@ -444,15 +445,11 @@
} }
} }
private void GetJwtToken(Alias alias) private async Task GetJwtToken(Alias alias)
{ {
_authorizationToken = Context.Request.Headers[HeaderNames.Authorization]; // bearer token may have been provided by remote Identity Provider and persisted using SaveTokens = true
if (!string.IsNullOrEmpty(_authorizationToken)) _authorizationToken = await Context.GetTokenAsync("access_token");
{ if (string.IsNullOrEmpty(_authorizationToken))
// bearer token was provided by remote Identity Provider and was persisted using SaveTokens
_authorizationToken = _authorizationToken.Replace("Bearer ", "");
}
else
{ {
// generate bearer token if a secret has been configured in User Settings // generate bearer token if a secret has been configured in User Settings
var sitesettings = Context.GetSiteSettings(); var sitesettings = Context.GetSiteSettings();