Skip to content

Commit

Permalink
Merge pull request #18 from seanfisher/update-auth-options
Browse files Browse the repository at this point in the history
Update auth options and comments
  • Loading branch information
seanfisher committed Apr 14, 2022
2 parents 2f9f6e9 + 28959be commit c3dee11
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Example App",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/example/login/app.js"
}
]
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ Microsoft's developer site.

// [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 All @@ -69,7 +64,12 @@ application:

```js
app.get('/auth/microsoft',
passport.authenticate('microsoft'));
passport.authenticate('microsoft', {
// Optionally define any authentication parameters here
// For example, the ones in https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow

prompt: 'select_account',
}));

app.get('/auth/microsoft/callback',
passport.authenticate('microsoft', { failureRedirect: '/login' }),
Expand Down
5 changes: 4 additions & 1 deletion example/login/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ app.get('/login', function (req, res) {
// redirecting the user to the common Microsoft login endpoint. After authorization, Microsoft
// will redirect the user back to this application at /auth/microsoft/callback
app.get('/auth/microsoft',
passport.authenticate('microsoft'),
passport.authenticate('microsoft', {
// Optionally add any authentication params here
prompt: 'select_account'
}),
function (req, res) {
// The request will be redirected to Microsoft for authentication, so this
// function will not be called.
Expand Down
7 changes: 1 addition & 6 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function MicrosoftStrategy(options, verify) {
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';

OAuth2Strategy.call(this, options, verify)
this.name = 'microsoft'
Expand Down Expand Up @@ -79,16 +78,12 @@ util.inherits(MicrosoftStrategy, OAuth2Strategy)
MicrosoftStrategy.prototype.authorizationParams = function(options) {
var params = {};

['locale', 'display'].forEach(function(name) {
['locale', 'display', 'prompt', 'login_hint', 'domain_hint'].forEach(function(name) {
if (options[name]) {
params[name] = options[name]
}
});

if (options.prompt) {
params['prompt'] = options.prompt;
}

return params;
};

Expand Down

0 comments on commit c3dee11

Please sign in to comment.