Last active
May 11, 2024 09:40
-
-
Save LauraKokkarinen/b3abb04a6c963674a32de020f96f0423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Identity; | |
public async Task<string> GetAccessTokenAsync(string resourceUrl, string tenantId, string clientId, string clientSecret, string userAssertion, CancellationToken cancellationToken) | |
{ | |
// userAssertion is the access token this API received from its caller | |
// You can also use a certificate instead of client secret | |
var credential = new OnBehalfOfCredential(tenantId, clientId, clientSecret, userAssertion); | |
// The passed in cancellation token can be used by the caller to cancel the request | |
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(scopes: [resourceUrl + "/.default"]) { }, cancellationToken); | |
return accessToken.Token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment