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

Commit 9d15dcd

Browse files
committed
Modify Microsoft AuthN lookup option to use username (required) vs email (not required)
1 parent c372515 commit 9d15dcd

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const axios = require('axios');
22

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

1717
function getSubject(decoded) {
18-
if (decoded.payload.hasOwnProperty('email')) {
19-
return decoded.payload.email;
18+
if (decoded.payload.hasOwnProperty('upn')) {
19+
return decoded.payload.upn;
2020
} else {
21-
return 'Email not found';
21+
return 'Username not found';
2222
}
2323
}
2424

build/build.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function microsoftConfiguration() {
6262
required: true
6363
},
6464
AUTHZ: {
65-
description: colors.red("Authorization methods:\n (1) Azure AD Login (default)\n (2) JSON Email Lookup\n\n Select an authorization method")
65+
description: colors.red("Authorization methods:\n (1) Azure AD Login (default)\n (2) JSON Username Lookup\n\n Select an authorization method")
6666
}
6767
}
6868
}, function(err, result) {
@@ -77,7 +77,7 @@ function microsoftConfiguration() {
7777
config.AUTH_REQUEST.redirect_uri = result.REDIRECT_URI;
7878
config.AUTH_REQUEST.response_type = 'code';
7979
config.AUTH_REQUEST.response_mode = 'query';
80-
config.AUTH_REQUEST.scope = 'openid email';
80+
config.AUTH_REQUEST.scope = 'openid';
8181

8282
config.TOKEN_REQUEST.client_id = result.CLIENT_ID;
8383
config.TOKEN_REQUEST.grant_type = 'authorization_code';
@@ -93,17 +93,17 @@ function microsoftConfiguration() {
9393
shell.exec('zip -q cloudfront-auth.zip config.json index.js package-lock.json package.json auth.js -r node_modules');
9494
break;
9595
case '2':
96-
shell.cp('./authz/microsoft.json-email-lookup.js', './auth.js');
96+
shell.cp('./authz/microsoft.json-username-lookup.js', './auth.js');
9797
prompt.start();
9898
prompt.message = colors.blue(">>>");
9999
prompt.get({
100100
properties: {
101-
JSON_EMAIL_LOOKUP: {
102-
description: colors.red("JSON email lookup endpoint")
101+
JSON_USERNAME_LOOKUP: {
102+
description: colors.red("JSON username lookup endpoint")
103103
}
104104
}
105105
}, function (err, result) {
106-
config.JSON_EMAIL_LOOKUP = result.JSON_EMAIL_LOOKUP;
106+
config.JSON_USERNAME_LOOKUP = result.JSON_USERNAME_LOOKUP;
107107
writeConfig(config, zipDefault);
108108
});
109109
break;

0 commit comments

Comments
 (0)