Search code examples
node.jsoauthoffice365adaloffice365-restapi

How to connect to office 365 via OAuth2 without redirect using node.js?


I have a Node.js app that connects to Microsoft Exchange via SOAP web services to use Calendar and Mail features.
Now, I want to do the same thing using REST API.

The problem is this app will be working in background so I already have user credentials and cannot redirect them to authentication page.

So far All I've found ADAL where you register your app in AZURE. But this requires a redirection.
Is there a way to connect to office 365 or Exchange online via OAuth2 and use REST API without having to redirect ?


Solution

  • According your description, you want to implement backend application against to Microsoft Graph via OAuth2. You can try to follow the client credentials work flow to integrate AAD in backend void redirect uri. You can refer to Call Microsoft Graph in a service or daemon app for more info.

    Meanwhile, as you are using ADAL for node.js, so you can try the second example in this repository Server to Server via Client Credentials, which follows client credentials grand flow to access token from AAD.

    Any further concern, please feel free to let me know.