[Question] How to get OBO token from an event handler
See original GitHub issueHow can I get an OBO access token in an event handler like:
[HttpPost]
public IActionResult ProcessData(string data)
{
var processor = new Processor();
processor.Finished += async (s, e) =>
{
var accessToken = await this
._tokenAcquisition
.GetAccessTokenForUserAsync(new[] { "Files.ReadWrite" }, user: this.User);
await WriteToOneDrive(accessToken, e.Data);
};
processor.processAsync(data); // Run async without awaiting
return NoContent();
}
In this case the this.User
is already disposed, and even without it, GetAccessTokenForUserAsync
crashes with NullObjectException.
My process takes a very long time (hours).
How can I get the token inside a callback when I need it?
Issue Analytics
- State:
- Created 3 years ago
- Comments:23 (3 by maintainers)
Top Results From Across the Web
get token in event handler · AzureAD/microsoft-identity-web ...
How to get an OBO token in an event handler or a long running process. Principle ... When the call is done, and...
Read more >Microsoft identity platform and OAuth 2.0 On-Behalf-Of flow
This article describes how to use HTTP messages to implement service to service authentication using the OAuth2.0 On-Behalf-Of flow.
Read more >MSAL.NET OBO refresh token problems - oauth 2.0
When it's called with the jwtBearerToken, it will successfully call AcquireTokenOnBehalfOf() and the token is cached and a result returned, but ...
Read more >MSAL Python 1.23.0 documentation
Handle a token obtaining event, and add tokens into cache. You can subclass it to add new behavior, such as, token serialization. See...
Read more >On-behalf-of flows with MSAL.NET
The OBO call is done by calling the AcquireTokenOnBehalfOf(IEnumerable<String>, UserAssertion) method on the IConfidentialClientApplication ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that the problem is that the HttpContext is null, or HttpContext.Items is null:
https://github.com/AzureAD/microsoft-identity-web/blob/41195539af65836b464b063c186842896ab15e0e/src/Microsoft.Identity.Web/HttpContextExtensions.cs#L30
We should probably guard against these cases:
as if the token is returned null, the AcquireTokenSilent will be tried, which should work for this scenario.
@jennyf19 @pmaytak @henrik-me I’m tempted to take this in 0.3.0-preview if you don’t mind, as this would unblock our partner.
Hi @jennyf19 I still can’t get a token inside a callback with the latest master (error below).
I’ve open a repo with sample code with repro of the problem here