c# - 具有 Dynamic 365 身份验证的 Azure 函数 - 无法加载类型 'System.Security.Cryptography.SHA256Cng'

标签 c# azure function authentication

我有一个 azure 功能/应用程序注册,在我尝试使用身份验证来获取 token 之前,该功能/应用程序注册一直在工作。我使用以下代码收到以下错误消息。

var requestedToken = authenticationResult.Result.AccessToken;

生成 idOne 时出现问题或发生更多错误。 (无法从程序集 System.Core、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b77a5c561934e089 加载类型 System.Security.Cryptography.SHA256Cng)

var aadInstance = "https://login.microsoftonline.com/";

string api = "https://interconservicesdev.crm.dynamics.com/api/data/v9.1";

AuthenticationParameters ap = AuthenticationParameters.CreateFromUrlAsync(
    new Uri(api)).Result;

string organizationUrl = "https://interconservicesdevdev.crm.dynamics.com";
string clientId = "SOME_CLIENT_ID";
string secertKey = "SOME_SECRET_KEY";
string tenantId = "SOME_TENANT_ID";

log.Info("Organization Url : " + organizationUrl);
log.Info("Client Id : " + clientId);
log.Info("Client Key : " + secertKey);
log.Info("Tenant Id : " + tenantId);

var clientcred = new ClientCredential(clientId, secertKey);
string combineString = aadInstance + tenantId;
log.Info("Combine String : " + combineString);

var authenticationContext = new AuthenticationContext(combineString, false);

log.Info("Authority : " + authenticationContext.Authority);

//AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);

var authenticationResult = authenticationContext.AcquireTokenAsync(organizationUrl, clientcred);
log.Info("Authentication Result : " + authenticationResult.IsCompleted + " " + authenticationResult.Id);

var requestedToken = authenticationResult.Result.AccessToken;
log.Info("Requested Token : " + requestedToken);

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

service = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl), new TimeSpan(0, 180, 0), false);
log.Info("Service : " + service.SdkClientVersion);
service.HeaderToken = requestedToken;

log.Info("Header Token : " + requestedToken);

enter image description here

enter image description here

最佳答案

从 VS 2017 切换到 2019 后,我已经能够解决我的问题。

关于c# - 具有 Dynamic 365 身份验证的 Azure 函数 - 无法加载类型 'System.Security.Cryptography.SHA256Cng',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63797784/

相关文章:

c# - 在 WebForms 中从 C# 更改 CSS 的菜单项

c# - 使用来自另一个 web api 的客户端证书调用 web api

c# - 查看WP7是否处于静音模式

asp.net - Windows azure 免费层后台处理?

c# - Azure Blob 元数据编码

azure - 将Web项目发布到azure失败: The "IsolatedCSPack" task failed unexpectedly

c# - 应用程序启动时将焦点放在 PasswordBox 上

javascript - React 组件状态的默认函数参数值

ios - 尝试在 Swift 中使用来自 CKRecord 的原始数据形式

c - 误解传递给 C 中函数的数组指针