我有一个 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);
最佳答案
从 VS 2017 切换到 2019 后,我已经能够解决我的问题。
关于c# - 具有 Dynamic 365 身份验证的 Azure 函数 - 无法加载类型 'System.Security.Cryptography.SHA256Cng',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63797784/