I have an azure function / App registrations that is working until I try to use Authentication to get a token. I am getting the following error message using the following code.
var requestedToken = authenticationResult.Result.AccessToken;
There is an issue while generating idOne
or more errors occurred. (Could not load type System.Security.Cryptography.SHA256Cng
from assembly System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
)
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 的问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.