I’m trying to get an access token via the azure-identity python package for accessing an Azure Service. I done the app registration in the Azure AD and I got the following C# code, which works as expected:
private static async Task<string> GetAccessToken(string aasUrl)
{
var tenantId = "<>";
var appId = "<>";
var appSecret = <>;
string authorityUrl = $"https://login.microsoftonline.com/{tenantId}";
var authContext = new AuthenticationContext(authorityUrl);
// Config for OAuth client credentials
var clientCred = new ClientCredential(appId, appSecret);
AuthenticationResult authenticationResult = await authContext.AcquireTokenAsync(aasUrl, clientCred);
//get access token
return authenticationResult.AccessToken;
}
But when I try to redo the C# in python, I can’t get the get_token(scode:str) to work…I simply do not get what scope to pass into the get_token function.
from azure.identity import ClientSecretCredential
authority = 'https://login.microsoftonline.com'
credential = ClientSecretCredential(tenant_id, client_id, client_secret, authority=authority)
token = credential.get_token(scope:str) #scope?
When I use the .net Microsoft.IdentityModel.Clients.ActiveDirectory library I don’t have to think about scope.