Closed mschaefer-gresham closed 1 year ago
You do not "Renew" and id-token without a user not being in front of your system. Your scenario might be addressed by this sample -> Share the MSAL token cache between a web app and a background console worker app
@kalyankrishna1 thanks for the response. Can you clarify what you mean by "without a user being in front of your system"?
Could incremental consent and conditional access be used to solve this problem?
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
I am trying to implement the BFF-Gateway pattern (no tokens in the browser) to be used with a React SPA. The BFF is using AddMicrosoftIdentityWebAppAuthentication to handle login and issue a cookie to the SPA. And it is using YARP to proxy api requests to a downstream api. I'm using Azure B2C. Everything works perfectly until the BFF id_token expires in 1 hour. At that point, fetching the downstream api access token via tokenAcquisition.GetAccessTokenForUserAsync (which is called in a piece of middleware) fails:
Exception:
This is effectively the same as Call Downstream API Without The Helper Class example and this sample, except that I'm acquiring the access token in middleware, not a controller, so the downstream YARP requests contain the access token. BTW I get the same error if I do this inside a controller per this example. And I see no soluton to this in the sample.
There is a similar question here which references this sample, but for the B2C sample I see no solution to this problem.
I also found this sample and this explanation. But this uses Microsoft.Owin to configure auth, not AddMicrosoftIdentityWebAppAuthentication. This looks promising, but is a departure from most examples I see that use Microsoft.Identity.Web.
Can you please point to the correct soluton? I need call to be able to call _tokenAcquisition.GetAccessTokenForUserAsync after the id token expires without asking the user to reauthenticate and/or the SPA to having to reload.
Any log messages given by the failure
OS and Version?
Versions
Attempting to troubleshooting yourself:
Mention any other details that might be useful