Get AccessTokenOnBehalfOfUser if (Current)HttpContext is not available (anymore) #10
Closed
1 of 14 tasks
Labels
Milestone
From @pocki and copied from Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2#233
This issue is for a: (mark with an
x
)The issue was found for the following scenario:
Please add an 'x' for the scenario(s) where you found an issue
Repro-ing the issue
Repro steps
Is it somehow possible to receive an AccessToken on behalf of User if only (at least) ClaimsPrincipal (like in #159) is available but no full (Current)HttpContext?
Why: I have a long running task moved to a IHostedService. In this service I need an AccessToken at beginning and at the end (for the same scope). The AccessToken for the beginning is no problem, I can request it before the start and/or use the TokenCache. But in the end (>1 hour after begin) of the HostedService the token needs to be refreshed, but I can not call the TokenAcquisition because HttpContext is not available (out of Scope/Disposed) in IHostedService.
Actually I use
TokenAcquisition.GetAccessTokenOnBehalfOfUserAsync
to get and to "refresh"/get a new tokenExpected behavior
Use of
TokenAcquisition.GetAccessTokenOnBehalfOfUserAsync
where HttpContext is not available (Disposed or out of Scope)Actual behavior
With modifications of #159 I can pass the HttpContext.User as a Parameter to the HostedService: System.NullReferenceException "Object reference not set to an instance of an object."
Line numbers may not match with this Repo
Possible Solution
Is it possible to set needed values for TokenAquisition manually?
Is there another method instead of
TokenAcquisition.GetAccessTokenOnBehalfOfUserAsync
to refresh a token?Versions
Mention any other details that might be useful
Is there any other possiblity? Have I missed something? Anyone another suggestion how to solve this?
The text was updated successfully, but these errors were encountered: