File Mover Blog

October 23, 2022

How to access SharePoint Rest API using OAuth

Version v2023 is needed and available here.

This Authorization method using OAuth2 was tested by a customer of us (Eddy, we really appreciate this). It is based on the following article.

As mentioned in the article, first you’ll need to register an AD app with your AD Tenant. It will assign you the necessary information you need for the OAuth2 setup

Feedback customer:

  • This required the following settings in Azure. Maybe only the delegated permissions under Graph are enough, didn’t play too much.

Sharepoint OAuth2 authorization

  • Also the the redirect url should be set for the app, and ID_token must be enabled.

Sharepoint OAuth2 authorization

Limagito File Mover Setup:

  • In this case the Auth Type in our SharePoint setup should be set to: ‘OAuth 2.0 Authorization Code Flow’

SharePoint OAuth Authentication

  • OAuth2 Setup:
    • Disable ‘Code Challenge’
      • Seems to work also when enabled (tested by customer)
    • Enable ‘Include Nonce’
    • Set ‘Authorization Endpoint URL’
      • https://login.microsoftonline.com/%realm/oauth2/authorize
      • %realm will be replaced by the Realm value (= Tenant or Tenant_ID). You can also enter the full URL including the Tenant.
    • Set ‘Token Endpoint URL’
      • https://login.windows.net/%realm/oauth2/token?api-version=1.0
      • %realm will be replaced by the Realm value (= Tenant or Tenant_ID). You can also enter the full URL including the Tenant.
    • Enter your Client ID and Client Secret (please check the article howto create them)
    • Set ‘Scope’ to:  openid
      • If you don’t receive a Refresh Token, change it to:  openid offline_access
      • Customer used: https://<Tenant>.sharepoint.com/.default
    • Set ‘Resource’ to:  https://graph.microsoft.com/
      • Customer used: https://<Tenant>.sharepoint.com
    • Set Response Mode to:  form_post
    • Set Response Type to:  id_token+code
    • When using %realm in the ‘Authorization or Token Endpoint URL’
      • Please set ‘Realm’ to your Tenant of Tenant_ID

After the setup, please click on the <Get> button. If you get a firewall popup, you’ll need to accept this otherwise we will not be able to capture the Tokens.

Follow the steps in the browser and it should fill the Refresh and Access Token afterwards. Do not forget to click <Save>.

SharePoint OAuth Authentication

Our customer used different Scope and Resource values:

Sharepoint OAuth2 Auhorization

  • Common Setup:

If you want extra debug information during the test, please enable ‘Add Control Information to Log’

SharePoint OAuth Authentication

#Filetransfer #SharePoint

If you need any help with this ‘how-to-access-sharepoint-rest-api-using-oauth’ option, please let us know.

Best Regards,

Limagito Team

By Limagito-Team OAuth2 SharePoint , , , Share: