This module lets you authenticate using Outlook REST API v2 in your Node.js applications. By plugging into Passport, Outlook REST API v2 authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
Unlike alternative modules, this package authenticates against the latest Outlook.com (Office 365) v2 endpoints as can be tested in their Outlook Dev Center OAuth Sandbox
$ npm install --save passport-outlook
Upgrading for v2
If you were using the package before
v2.0.0, please note that the
JSON returned has been updated to match the normalized contact schema outlined
by Passport and used by other strategies.
Therefore, you will need to update your application to match these modified JSON properties.
Create an Application
passport-outlook, you must register an application with Microsoft.
If you have not already done so, a new application can be created at the
Application Registration Portal. Your
application will be issued a client ID and client secret, which need to be
provided to the strategy. You will also need to configure a redirect URL which
matches the route in your application.
The Outlook REST API v2 authentication strategy authenticates users using an
Outlook.com account and OAuth 2.0 tokens. The strategy requires a
callback, which accepts these credentials and calls
done providing a user,
as well as
options specifying a client ID, client secret, and callback URL.
If you want to use the express request, you must use the option
passReqToCallback: true, then Passport will send the request as the first parameter.
passport.authenticate(), specifying the
'windowslive' (or custom named)
strategy, to authenticate requests.
For example, as route middleware in an Express application:
REST API specific scopes you are using must be fully qualified to match the
outlook domain, e.g:
https://outlook.office.com/Mail.Read instead of
This is very important, otherwise you will receive
'offline_access' is a required scope in order to obtain a
refresh_token. More information is available in the MSDN Dev Center.
If you need to customise the URLs used by the strategy (such as
connecting to the Microsoft Graph
API instead of Office365 REST) this is possible by modifying the
options passed to the strategy:
In the example above the strategy
name is changeed from the default of
'msgraph' and the
userProfileURL is changed to the correct Microsoft Graph
API endpoint. If you make this change, please remember to use the appropriate scopes
for the API.
For a complete, working example, refer to the login example.
Any system can run the test suite in development from the terminal.
$ npm install$ npm test
The test suite is located in the
test/ directory. All new features are
expected to have corresponding test cases. Ensure that the complete test suite
passes by executing:
$ make test
All new features are expected to have test coverage. Patches that increase test coverage are happily accepted. Coverage reports can be viewed by executing:
$ make test-cov$ make view-cov
Copyright (c) 2015-2019 Nigel Horton