Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

AuthType = ClientSecret CurrentAccessToken abnormal

Posted on by

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

1663.png

  • Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: AuthType = ClientSecret CurrentAccessToken abnormal

    HI,

    Glad that it solved your issue.

    Please mark my answer verified.

  • RE: AuthType = ClientSecret CurrentAccessToken abnormal

    Thank you for your help

  • Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: AuthType = ClientSecret CurrentAccessToken abnormal

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans