Register app in Azure AD:
Login with Dynamics 365 and in a new tab browse the below URL:
The Azure portal home page will open, now from search input, search for Azure Active Directory.
Open Azure Active Directory by clicking on it.
To create the App, from the left menu click on App Register -> New registration.
The new app registration form will open, in the form enter the app name and click on Register.
After creating the app, a new app detail page will open. You need to copy the Application (client) ID from the detail for oAuth.
To provide Dynamics 365 API permission click on API permission from the left side menu then click on Add a Permission.
The side panel will open from where you can see Dynamics CRM permission by clicking on “Dynamics CRM”.
In the second screen, check the user_impersonation checkbox and then click on Add permission.
The permission for CRM common data service was added to the App.
To add Sharepoint permission click on Add New Permission and select Sharepoint
After that on the next screen click on Delegated Permission.
The Permission section will be visible, no expand AllSites and select AllSites.FullControl checkbox and then click on Add permission button to add sharepoint permission.
To grant user, click on Grant admin consent for [user].
Click on Authentication from the left menu.
After that click on Authentication from the left menu and in Advanced settings enable Allow public client flows by enabling the switch to Yes then click on Save.
After that to create a client secret for the app, click on Certificates & secrets from the left menu and then click on New client secret.
Add a description and select the client secret expiry time, click on Add to create a client secret.
After successfully client secret is added, it will display in the client secret list, from where you need to copy the client’s secret value(It is 1 time copyable) for oAuth.
Create Application User :
For creating Application user Login to https://admin.powerplatform.microsoft.com/environments/.
Next select Dynamics 365 Environment, then select Settings.
Redirect to Application users, under Users + permissions.
Click on New app user from the list of Application users.
From the Create a new app user, click Add an app and select the App you created earlier.
Select the Business unit to add the app user. Next, Select the Security roles to assign to the user.
Click Create, and see the user has been added to your environment.