Azure B2C Client credential flow
See original GitHub issueI can acquire a token from Azure B2C for client credential flow by performing an explicit request against the api e.g.
public class TokenClient : ITokenClient
{
private readonly HttpClient httpClient;
private readonly AzureB2COptions options;
public TokenClient(HttpClient httpClient, AzureB2COptions options)
{
this.httpClient = httpClient;
this.options = options;
}
/// <copydoc cref="ITokenClient.GetToken" />
public async Task<string> GetToken(string appIdUri = "")
{
if (string.IsNullOrEmpty(appIdUri))
{
appIdUri = options.AppIdUri;
}
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("client_id", options.ClientId),
new KeyValuePair<string, string>("client_secret", options.ClientSecret),
new KeyValuePair<string, string>("scope", $"https://{options.Tenant}/{appIdUri}/.default")
});
// Throw errors on invalid response, allows retry/policy wrapping etc
var requestResult = await httpClient.PostAsync($"/{options.Tenant}/oauth2/v2.0/token", content);
requestResult.EnsureSuccessStatusCode();
var contentResult = await requestResult.Content.ReadAsStringAsync();
var json = JObject.Parse(contentResult);
var accessToken = (string)json["access_token"];
return accessToken;
}
}
Is there a way to use ADAL to issue the same request?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Set up OAuth 2.0 client credentials flow - Azure AD B2C
In the client credentials flow, permissions are granted directly to the application itself by an administrator. When the app presents a token to ......
Read more >Azure B2C client credentials grant
I've implemented Azure B2C for user login/logout and can get the id_token and pass it to my web API for authorization, all works...
Read more >Client Credentials Grant Flow with Azure AD B2C
In the Azure AD B2C - App registrations page, select the application you created, for example webapp1. · In the left menu, under...
Read more >Deploy Client Credential Flow for Azure Active Directory
The Client Credential Flow option for Azure Active Directory (AD) in the Cloud Identity Engine allows you to use a service account to...
Read more >Secure communication between apps registered in the ...
Secure communication between apps registered in the Azure AD B2C using OAuth 2.0 client credentials flow.
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
@phatcher, for client credentials, you might want to look at Acquiring a token for the app with client credentials flow)
A non-B2C sample is available from https://github.com/azure-samples/active-directory-dotnet-daemon-v2
Closing this, please open or reply if you have more questions.