Reputation: 23
Are there any code samples of how to access the AzureAdB2C token for later use in Azure function calls? The web project has already incorporated the Azure authentication using OpenIdConnect. The following is the setup in Startup.cs:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAdB2C(options => Configuration.Bind("Authentication:" + AzureCompany, options))
.AddCookie();
Upvotes: 0
Views: 127
Reputation: 27588
Not sure about your requirement , but with OIDC middleware , you can set SaveTokens
to true :
services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.OpenIdScheme, options =>
{
...
options.SaveTokens = true;
...
});
Put above config below B2C authentication , and after user is authenticated , you can get that in controller like :
string idToken = await HttpContext.GetTokenAsync("id_token");
Upvotes: 1
Reputation: 1197
I would not recommend this approach, correct me if I am wrong, you are trying to use same Bearer token for function app authentication?
instead of this you can generate a new token for function app, and use that.
you can generate a token using ms APIs.
For more info -> https://westerndevs.com/Functions-aad-authentication/
Request a token Guide-> https://learn.microsoft.com/en-us/azure/active-directory-b2c/access-tokens
Upvotes: 0