-
Notifications
You must be signed in to change notification settings - Fork 55
Closed
Description
It's fairly trivial^ to hook up Azure.Identity in code, but it'd be nice if the connection string supported managed identity directly.
^ I'm not sure this handles token caching correctly
var factory = new AzureIdentityOrgSvcFactory(new ("https://....dynamics.com"), new Azure.Identity.DefaultAzureCredential(), logger);
class AzureIdentityOrgSvcFactory : IOrganizationServiceFactory
{
readonly Uri uri;
readonly TokenCredential tokenCredential;
readonly ILogger logger;
public OrgSvcFactory(Uri uri, TokenCredential tokenCredential, ILogger logger)
{
this.logger = logger;
this.uri = uri;
this.tokenCredential = tokenCredential;
}
public IOrganizationService CreateOrganizationService(Guid? userId)
{
var c = new Microsoft.PowerPlatform.Dataverse.Client.ServiceClient(uri, GetToken, logger: logger);
if (userId is Guid callerId)
c.CallerId = callerId;
return c;
}
async Task<string> GetToken(string instance)
{
var option = new TokenRequestContext(new[] { uri.AbsoluteUri + ".default" });
var token = await tokenCredential.GetTokenAsync(option, default);
return token.Token;
}
}Metadata
Metadata
Assignees
Labels
No labels