Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Modify Microsoft AuthN lookup option to use username (required) vs em…
Browse files Browse the repository at this point in the history
…ail (not required)
  • Loading branch information
payton committed Feb 7, 2018
1 parent c372515 commit 9d15dcd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const axios = require('axios');

function isAuthorized(decoded, request, callback, unauthorized, internalServerError, config) {
axios.get(config.JSON_EMAIL_LOOKUP)
axios.get(config.JSON_USERNAME_LOOKUP)
.then(function(response) {
if (Array.isArray(response.data) && response.data.indexOf(decoded.sub) > -1) {
callback(null, request);
Expand All @@ -15,10 +15,10 @@ function isAuthorized(decoded, request, callback, unauthorized, internalServerEr
}

function getSubject(decoded) {
if (decoded.payload.hasOwnProperty('email')) {
return decoded.payload.email;
if (decoded.payload.hasOwnProperty('upn')) {
return decoded.payload.upn;
} else {
return 'Email not found';
return 'Username not found';
}
}

Expand Down
12 changes: 6 additions & 6 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function microsoftConfiguration() {
required: true
},
AUTHZ: {
description: colors.red("Authorization methods:\n (1) Azure AD Login (default)\n (2) JSON Email Lookup\n\n Select an authorization method")
description: colors.red("Authorization methods:\n (1) Azure AD Login (default)\n (2) JSON Username Lookup\n\n Select an authorization method")
}
}
}, function(err, result) {
Expand All @@ -77,7 +77,7 @@ function microsoftConfiguration() {
config.AUTH_REQUEST.redirect_uri = result.REDIRECT_URI;
config.AUTH_REQUEST.response_type = 'code';
config.AUTH_REQUEST.response_mode = 'query';
config.AUTH_REQUEST.scope = 'openid email';
config.AUTH_REQUEST.scope = 'openid';

config.TOKEN_REQUEST.client_id = result.CLIENT_ID;
config.TOKEN_REQUEST.grant_type = 'authorization_code';
Expand All @@ -93,17 +93,17 @@ function microsoftConfiguration() {
shell.exec('zip -q cloudfront-auth.zip config.json index.js package-lock.json package.json auth.js -r node_modules');
break;
case '2':
shell.cp('./authz/microsoft.json-email-lookup.js', './auth.js');
shell.cp('./authz/microsoft.json-username-lookup.js', './auth.js');
prompt.start();
prompt.message = colors.blue(">>>");
prompt.get({
properties: {
JSON_EMAIL_LOOKUP: {
description: colors.red("JSON email lookup endpoint")
JSON_USERNAME_LOOKUP: {
description: colors.red("JSON username lookup endpoint")
}
}
}, function (err, result) {
config.JSON_EMAIL_LOOKUP = result.JSON_EMAIL_LOOKUP;
config.JSON_USERNAME_LOOKUP = result.JSON_USERNAME_LOOKUP;
writeConfig(config, zipDefault);
});
break;
Expand Down

0 comments on commit 9d15dcd

Please sign in to comment.