Before start, you can read through - "What is Microsoft Graph" to get an overview of Microsoft Graph. Microsoft Graph is the gateway to data and intelligence in Microsoft 365. It provides a unified programmability model that you can use to access the tremendous amount of data in Microsoft 365, Windows, and Enterprise Mobility + Security.
In this article, I will explain how to use webMethods.io Microsoft onedrive connector using Microsoft Graph. To create a connection for this connector we need below details.

So to start with we need to get Client ID, Client Secret, Access Token, Refresh Token, Refresh URL for the App registered with Microsoft Azure through Azure App registration page.
I will go through step by step here following this link.
1) First need to register an app through Azure App registration page.
Give any name of the App. Then supported Account types selected as Accounts in any Organization Directory to support multitenant url to get authorization code and token. If it can not be done, and need to select Accounts in the organizational directory only ( Single tenant), then also it will work. In that case only difference in the URL will be instead of "common", you need to provide your tenant ID of the app.


You can provide App permission as it is needed.

Then generate a client secret

For Redirect URL, I have added my webMethods.io tenant url

Once this is done, Please copy client ID, client Secret, Tenant ID (Directory (tenant) ID) , Redirect URL from this App, which will be required to get Authorization code, Access Token and Refresh Token

Value will be the client secret not secret ID

2) Getting Authorization Code
From this link , will follow code flow

First step is to get authorization code
GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope}&response_type=code&redirect_uri={redirect_uri}
Need to form this URL with client ID, Scope and Redirect URL
Here is one sample, I have provided client ID, Scope as ( files.readwrite offline_access ) as I want to access onedrive. Redirect URL should be same as given in the app
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=xxxxxxxxxx68a665&scope=files.readwrite%20offline_access&response_type=code&redirect_uri=https%3A%2F%2Fxxxdev.int-aws-us.webmethods.io%2F
Once you hit the url through browser, it will ask you to login to authorize
Once authorized, it will redirect to the URL with the code returned in the URL

From the URL copy the code value.
Now if app created was not Multi-tenant, but single tenant. Then the URL will be changed. just replace "common" with the tenant ID from the App overview.
https://login.microsoftonline.com/xxxxxxxx9-bbfa-9a828bcc920d/oauth2/v2.0/authorize?client_id=a61bdeaa-b8cd-4987-87cf-fddd9268a665&scope=files.readwrite%20offline_access&response_type=code&redirect_uri=https%3A%2F%2Fxxxxxxdev.int-aws-us.webmethods.io%2F
3) Get the access token and refresh token
Now using client ID, Client Secret, Authorization code can get Access Token, Refresh Token
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}
&code={code}&grant_type=authorization_code

If app is not supported for Multi tenant then as we have done for authorization code , this URL will be changed
https://login.microsoftonline.com/xxxxxxxx9-bbfa-9a828bcc920d/oauth2/v2.0/token
instead of common it will be the tenant ID
4) Creation workflow and connection for Microsoft Onedrive webMethods.io Connector
Now we have client ID, client Secret, Access Token, Refresh token - can create the connection in webMethods.io Microsoft one drive connector
I have created a workflow, by simply dragging one drive connector in the workflow canvas.
Then under Authorize Microsoft One Drive, click "+" icon and select (Or) - create account using service access instead of Default authorization..


Refresh URL will be changed if the app is not Multi tenant based.
https://login.microsoftonline.com/xxxxxxxx9-bbfa-9a828bcc920d/oauth2/v2.0/token
5) Testing the workflow with Microsoft One drive connector
After creating the connection, select action from the available action from Microsoft One Drive connector
I have selected Get Folder Items
As Workflow is test driven approach, each step we can test individually. So here will test this step if able to pull folder items. This way it also create an output structure by itself to be available for consecutive steps in the workflow.

Click Next
It will read all the folders and select specific Folder ID
Then Next and click on Test
It returns the result

Now we can run this workflow end to end
It list all the folder Items

As we are using Refresh Token so this connector will automatically refresh token.