AAD B2C: Get New Access Token using Microsoft.AspNetCore.Authentication.OpenIdConnect

Carol Lai 526 Reputation points
2021-10-11T19:45:33.63+00:00

I'm using Microsoft.AspNetCore.Authentication.OpenIdConnect in my code to get ID Token, Code and Token. For OpenIdConnectOptions, I have set ResponseType to "code id_token token"
139555-openidoption-responsetype.png
and the scope to "openid, profile, and offline_access"
139500-openidoption-scope.png

I use a custom policy to login with MFA support to AAD B2C. Upon successful login, I receive ID Token, Code and Access Token. I don't receive a refresh token. I store away the ID Token, Code, and Access Token in OnTokenValidated event. I use the stored Access Token to access resources. When the Access Token expires, what method do I use to get a new Access Token?

I'm able to obtain the Refresh Token when I call HttpContext.GetTokenAsync("refresh_token").Result on my Razor page.
I use Microsoft.Identity.Web.UI to handle sign in and sign out.

I have tried to call HttpContext.SignInAsync() or HttpContext.AuthnticateAsync(). I still the same old Access Token.

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,892 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,902 questions
0 comments No comments
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.