NOTE: This is just a sample and is not being actively maintained and should not be considered production ready code
Sample using OpenID connect sample and the XRM tooling library to connect to Dynamics365.
Built upon an ASP.NET AAD Sample and using the OAuth behalf of flow to connect to the Common Data Service.
In this sample a user will login to Azure Active Directory, within the code there will then be another call out to AAD to get a token for Dynamics/CDS. See Utils/OnBehalfAuthManager.cs for more details.
To register your application and add the app's registration information to your solution manually, follow these steps:
- Sign in to the Azure portal using either a work or school account, or a personal Microsoft account.
- If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the desired Azure AD tenant.
- Navigate to the Microsoft identity platform for developers App registrations page.
- Select New registration.
- When the Register an application page appears, enter your application's registration information:
- In the Name section, enter a meaningful application name that will be displayed to users of the app, for example ASPNET-XRM-Quickstart.
- Add https://localhost:44301/ in Redirect URI, and click Register.
- Make sure there is a / at the end
- From the left navigation pane under the Manage section, select Authentication
- Under the Implicit Grant sub-section, select ID tokens.
- And then select Save.
- After it has saved from the left naivgation under the Manage section, select API Permissions
- Select Add a permission
- Find Dynamics CRM (under Microsoft APIs)
- Select user_impersonation
- Click Add permissions at the bottom of the page
- If you are an admin you can click Grant Admin Consent from Microsoft
- This will save you having to Grant consent upon initial sign in
- From the left naivgation under the Manage section, select Certificates & secrets
- Click New Client secret, provide a name and click add
- Note the value somewhere (this will not appear again after you leave the page)
- From the left naivgation select Overview
- Note doen the Application (client) ID and Directory (tenant) ID. These will both need to be added to the Web.config
- Download the repository from Github
- Open the solution in Visual Studio (OpenIdConnect-XRMTooling-Sample.sln)
- Depending on the version of Visual Studio, you might need to right click on the project OpenIdConnect-XRMTooling-Sample and Restore NuGet packages
- Open the Package Manager Console (View -> Other Windows -> Package Manager Console) and run Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
- Edit Web.config and fill in the values for ClientId, Tenant, AppSecret with the values from steps 7 and 8 from Registering your Application
- Replace the value of ResourceUri with the URL to your own Dynamics CRM
- Run the project and navigate to https://localhost:44301/ in an incognito browser
- This should pop up a page with a sign in button.
- Sign in as a user that is within your AAD tenant