Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

D365 authentication type OAuth not working with own app registration

Posted on by Microsoft Employee

I have been using AuthType as Office365 for my applications that communicates with Dynamics Crm, but since it is deprecated I have replace my connectionstring as follows:

Old:

<add key="CrmConnectionString" value="AuthType=Office365;Url=https://myenvironment. crm11.dynamics.com/;Username=myuseraccount@test.onmicrosoft.com;Password=Pa55word"/>

New:

<add key="CrmConnectionString" value="AuthType=OAuth;Username= myuseraccount@test.onmicrosoft.com; Password=Pa55word;Url= myenvironment.crm11.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Never"/>

This works fine using the above default AppId and RedirectUri that Microsoft has provided. But I want to use my own AppId and therefore I created App Registration in Azure with all the configuration settings given in Microsoft doc Tutorial: Register an app with Azure Active Directory (Microsoft Dataverse) - Power Apps | Microsoft Docs.

I have replaced the AppId above with my AppId in Azure and has no RedirectUri so I left that blank. The code I am using is below:

CrmServiceClient conn = new CrmServiceClient(System.Configuration.ConfigurationManager.ConnectionStrings["MyCrm"].ConnectionString);
IOrganizationService orgService = (IOrganizationService)conn;

I am using Microsoft.CrmSdk.XrmTooling.CoreAssembly version 9.1.0.79

So when I try to create the connection, it throws the following error:

ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error
AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
Trace ID: b901ed4b-bce4-44db-b20c-379317e52001
Correlation ID: ad84567a-99ac-4f02-b966-42f4f20642e7

Do I need anything else in connectionstring or the code? I don't want to use the ClientSecret Authtype because I need to pass the userid who will be talking to Crm.

Please suggest.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 authentication type OAuth not working with own app registration

    Hi Lalupatey,

    You can mark the answer as verifed through clicking 'Yes'.

    pastedimage1630891051356v1.png

    Thanks !

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 authentication type OAuth not working with own app registration

    I was trying to do that but I don't see "Please mark as verifed...." option anywhere. Please suggest.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 authentication type OAuth not working with own app registration

    Hi Partner,

    Please click Yes under "Did this answer your question?" to close this thread if my answer is helpful.

     pastedimage1624842655447v1.png

    Thanks. 

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 authentication type OAuth not working with own app registration

    Also I added my own Redirect URI

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 authentication type OAuth not working with own app registration

    Thank you so much for the link you provided.

    I updated the Redirect URIs and set the "Default Client type" to Yes for Authentication and it works.

  • NoellaB Profile Picture
    NoellaB 165 User Group Leader on at
    RE: D365 authentication type OAuth not working with own app registration

    Hello there,

    I believe that the missing part is not initializing a client secret key in your newly created application in Azure. Please refer to this link for further explanation: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/walkthrough-register-app-azure-active-directory

    And here's a link on  how you can add an application client secret key: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-oauth#use-client-secrets--certificates 

    If this helps, please make sure to verify my answer.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans