Hi, experts, I'm doing an authentication, the console program authentication is successful, and the authentication in the web application fails
'“crmServiceClient.CurrentAccessToken” Type raised “System.NullReferenceException” The abnormality of
Hi, experts, I'm doing an authentication, the console program authentication is successful, and the authentication in the web application fails
'“crmServiceClient.CurrentAccessToken” Type raised “System.NullReferenceException” The abnormality of
HI,
Glad that it solved your issue.
Please mark my answer verified.
Thank you for your help
Hi,
You should use below code get access token for WEB API.
//Azure Application Client ID
private const string ClientId = "00000000-0000-0000-0000-000000000000";
//Azure Application Client Key Secret
private const string ClientSecret = "SECRET VALUE FROM AZURE";
//Resource CRM Url
private const string Resource = "test.crm.dynamics.com";
//Guid is your Azure Active Directory Tenant Id private const string Authority = "login.microsoftonline.com/00000000-0000-0000-0000-000000000003";
private static AuthenticationResult _authResult;
public static string GetAccessToken() { string accessToken = string.Empty; AuthenticationContext authContext = new AuthenticationContext(Authority); //No prompt for credentials ClientCredential credentials = new ClientCredential(ClientId, ClientSecret); _authResult = authContext.AcquireToken(Resource, credentials); return _authResult.AccessToken; }
Please mark my answer verified if i were helpful
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156