Microsoft One Drive provides lot of benefits on the cloud by managing the documents from multiple systems and provides integration capabilities with Microsoft software products. 

Here I am going to explain leveraging the benefits of both Liferay Document Library & Microsoft One Drive.

Let’s consider a use case that Liferay portal is implemented as Intranet / Partner / Customer portal where some of the users have the documents in the One Drive.

Now if they want to have one common interface to manage the personal documents in One Drive and official documents in Liferay Document & Media Library then this article contains the detailed implementation & integration of One Drive Repository so that user can have flexibility & features from both the repository.

Develop Hook for Document & Media Library to invoke custom struts action to access the One Drive API.

Now Create the account in the Microsoft One Drive and register the application in the system for ex:- name of the application is LR portal. Now generate the Client ID & Client Secret Key to be shared with Liferay portal in order to authenticate.


Please find below the details of integrate with One Drive API:-


Client ID:

00000000401XXXXX - this is a unique identifier for your application.

Client secret (v1):

NA1HbvXXXXXXX2zRecXg32yaWfs69Jxh.  For security purposes, don't share your client secret with anyone.


Store clientID & secret in the file as it will be constant for all our webapp calls. 


Required query string parameters to be passed as per below:-


Name             Value  Description

client_id         string    The client ID value created for your application.   (00000000401XXXXX)

scope            string     A space-separated list of scopes your application requires. (wl.signin wl.offline_access onedrive.appfolder)

redirect_uri    string    The redirect URL that the browser is sent to when authentication is complete.                              (


For Ex:- 

scope:- wl.signin wl.offline_access onedrive.appfolder


Token flow




You will get access token as a response from the one drive and then you can make subsequent REST API calls by providing the access_token through HTTP Header. For ex:-

You provide an access token through an HTTP header:-

Authorization: bearer {token}



Upon successful authentication and authorization of your application, the web browser will be redirected to your redirect URL with additional parameters added to the URL.




Values for access_token, authentication_token, and user_id are truncated in the previous example. The values for access_token and authentication_token are quite long.

You can use the value of access_token to make requests to the OneDrive API.


One Drive:-

Get user's default Drive metadata   GET /drive /drive

LR needs to pass the Access Token along with GET request to One Drive API in order to get the response from the One Drive Server.


Now to get the specific user data through REST API, below is the sample of the call:-


GET bearer EwBwAq1DBAAUGCCXc8wU/zFu9QnLdZXy+YnElFkAAfhaFv0WOrA5dZ30IlgqQl+Fu2b5GzVSImo0hTflXN54xfJuu8ar1H1M+


Each client in portal will have the unique Access token to their Drive objects. Below diagram depicts the process to get the objects from One Drive:- 







Sequence Diagram: -

The below Sequence diagram explains the GET & POST  calls to obtain Tokens & Resources using OAuth & Rest API -






The flow of integration at the API level is mentioned below: -

 OneDrive uses OAuth 2.0 for authentication. LR will get an access token to authenticate with a particular set of permissions for a LR user. LR will provide an access token through an HTTP header:

                                                                    Authorization: bearer {token}

 The OneDrive API exposes below resource types: 

  • Drive – Drive for the user.
  • Item – files, folders.


1)  Root resources

LR will get root resources to access an item or drive.




User's default Drive.


List Drives available to the authenticated user.


Access a specific Drive by its ID.


List items in the root of a specific Drive.


Access an Item by its ID.



2)  Drive resource

The Drive is the top level object within a user's OneDrive. LR user will always have at least one Drive available--the default Drive. 

 Below are the examples to use /drive   along with /drives/ {drive-id} is valid too.


Common API details

HTTP method

Get user's default Drive metadata

GET /drive

Get Drive metadata of another Drive

GET /drives/{drive-id}

Get root folder for user's default Drive

GET /drive/root

List children under the Drive

GET /drive/root/children

List changes for all Items in the Drive

GET /drive/root/

Search for Items in the Drive (preview)

GET /drive/root/




3)   Item resource

Items are the objects inside the OneDrive file system. LR can access the items by their id using the /items/{item-id} syntax, or by their file system path using the /drive/root:/path/to/file syntax. 

Folders act as containers of items, and have a children reference pointing to a collection of items under the folder.   


Common task

HTTP method (by ID)

HTTP method (by path)

Get metadata for an Item

GET /drive/items/{id}

GET /drive/root:/{path}