Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tenant option. #17

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@ Microsoft's developer site.
```js
var MicrosoftStrategy = require('passport-microsoft').Strategy;
passport.use(new MicrosoftStrategy({
// Standard OAuth2 options
clientID: 'applicationidfrommicrosoft',
clientSecret: 'applicationsecretfrommicrosoft',
callbackURL: "http://localhost:3000/auth/microsoft/callback",
scope: ['user.read']
scope: ['user.read'],

// Microsoft specific options

// [Optional] The tenant for the application. Defaults to 'common'.
// Used to construct the authorizationURL and tokenURL
tenant: 'common',

// [Optional] The authorization URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize`
authorizationURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',

// [Optional] The token URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`
tokenURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',

// [Optional] Prompt. Defaults to 'select_account'
// Some options: 'login', 'none', 'select_account', and 'consent'
// A good description of the options here: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow
prompt: 'select_account'
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ userId: profile.id }, function (err, user) {
Expand Down
7 changes: 4 additions & 3 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ var InternalOAuthError = require('passport-oauth2').InternalOAuthError

function MicrosoftStrategy(options, verify) {
options = options || {}
options.authorizationURL = options.authorizationURL || 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
options.tokenURL = options.tokenURL || 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
const tenant = options.tenant || 'common';
options.authorizationURL = options.authorizationURL || `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize`;
options.tokenURL = options.tokenURL || `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`;
options.scopeSeparator = options.scopeSeparator || ' ';
options.customHeaders = options.customHeaders || {};
//options.prompt = options.prompt || 'select_account';
options.prompt = options.prompt || 'select_account';

OAuth2Strategy.call(this, options, verify)
this.name = 'microsoft'
Expand Down