question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure B2C Client credential flow

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jmprieurcommented, Jul 26, 2018
0reactions
bgavrilMScommented, Jul 26, 2018

Closing this, please open or reply if you have more questions.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found