我有一个 Power Automate 流程,其中我使用以下正文调用 https://login.microsoftonline.com/{tenantId}/oauth2/token:
grant_type=client_credentials
&client_id={clientId}
&client_secret={clientSecret}
&resource={app_registration}
我从调用中收到的访问令牌正在发送到需要连接到 Dynamics CRM 的 Azure Function 应用程序。 Azure 函数尝试使用相同的 ClientId 和 ClientSecret 并使用收到的不记名令牌作为
new Userassertion(req.GetBearerToken())
再次调用 Microsoft 身份平台
Azure Function中完整的相关代码如下:
AuthenticationContext authContext = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}");
ClientCredential credential = new ClientCredential("{clientId}", "{clientSecret}");
AuthenticationResult res = await authContext.AcquireTokenAsync("https://admin.services.crm.dynamics.com/user_impersonation", credential, new UserAssertion(req.GetBearerToken()));
string bearerTokenforCRM = res.AccessToken;
已发送静默登录请求,但没有用户登录
我认为我无法使用从 Flow 应用程序中的 /token 调用获取的承载令牌来代表启动 Flow 应用程序的用户获取新令牌。
在Azure中的应用程序注册中,我在菜单“Expose an Api”中添加了Azure功能,并在菜单API Permissions中添加了“Dyanmics CRM”,权限名称为“用户模拟”
我相信你的事情有点过于复杂 - 您可以使用带有 ClientId/ClientSecret 的连接字符串,以便使用以下 nuget 包连接到 Dataverse - https://www.nuget.org/packages/Microsoft.PowerPlatform.Dataverse .客户端 您可以使用以下文章来构建连接字符串 - https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm -工具连接 基本上它应该如下所示:
AuthType=ClientSecret;
url=https://contosotest.crm.dynamics.com;
ClientId={AppId};
ClientSecret={ClientSecret}