Log in to the Microsoft Sharepoint Online account.
Enter the following site or subsite URL:Site: https://<sitename.com>/_layouts/15/appregnew.aspxSubsite: https://<sitename.com>/<subsitedomain>/_layouts/15/appregnew.aspxThe App Information page appears.
Click Generate next to the Client Id field.The value of the client ID is displayed in the Client Id field. The following image shows the App Information page where you can generate the values of the client ID and client secret:
Click Generate next to the Client Secret field.The value of the client secret is displayed in the Client Secret field.
- Enter an appropriate title for the App in the Title field.
Enter an app domain name in the App Domain field.For example, www.google.com
Enter a URL in the Redirect URL field. For example, https://localhost/. You must enter the same redirect URL in the connection property.
The page redirects to the Microsoft Sharepoint Online page and the following message appears:The app identifier has been successfully created.The values of the client Id, client secret, title, and redirect URL are displayed.
Store the retrieved information (client id and client secret) since you'll need this in the next step!
follow this link for next step: Granting access using SharePoint App-Only | Microsoft Learn
If even with the correct ClientId and ClientSecret you have receiving the error:
The remote server returned an error: (401) Unauthorized.
the problem can be in Sharepoint settings, and can be fixed by the following PowerShell commands:
Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Connect-SPOService -Credential $creds -Url https://abakionmdi-admin.sharepoint.com -ModernAuth
$true -AuthenticationUrl https://login.microsoftonline.com/organizations
Set-SPOTenant -DisableCustomAppAuthentication $false