I'm creating an app that creates scheduled jobs programmatically, I am therefore using the REST API provided by Azure. I require an access token but when I authenticate, the access token returned from request expires that same time it is sent to me.
The client id is an application that I registered on Azure AD and copied the Application ID.
I created the secret key in the Keys blade.
I am using the AzureEnvironment.AzureGlobalCloud.AuthenticationEndpoint/{My Azure ID} as the authority (https://login.microsoftonline.com/)
I am requesting the access token for Azure Resource manager using AzureEnvironment.AzureGlobalCloud.ResourceManagerEndpoint.
private async Task<string> GetAccessToken()
{
_authContext = new AuthenticationContext($"{AzureEnvironment.AzureGlobalCloud.AuthenticationEndpoint}{ _jobConfig.TenantId}");
var credential = new ClientCredential(_jobConfig.AzureApplicationId, _jobConfig.AzureApplicationSecret);
var authResult = await _authContext.AcquireTokenAsync(AzureEnvironment.AzureGlobalCloud.ResourceManagerEndpoint, credential);
return authResult.AccessToken;
}
_jobconfig is an instance containing the data mentioned above and referenced in the code.