-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DPAT-1711 Change the userinfo js for nomis apps (#1211)
* DPAT-1711 Change the userinfo js for nomis apps * DPAT-1711 Minor change to fix the failed test * DPAT-1711 Removed the redundant token field * DPAT-1711 remove debug line
- Loading branch information
ymao2
authored
Nov 7, 2023
1 parent
bb90837
commit 8fafe38
Showing
3 changed files
with
14 additions
and
38 deletions.
There are no files selected for viewing
49 changes: 13 additions & 36 deletions
49
controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,14 @@ | ||
function(accessToken, ctx, cb) { | ||
var base_url = "{{gateway_url}}"; | ||
var user_endpoint = "/auth/api/user/me"; | ||
var user_profile_url = base_url + user_endpoint; | ||
|
||
// call oauth2 API with the accesstoken and create the profile | ||
request.get( | ||
user_profile_url, | ||
{ | ||
headers: { | ||
Authorization: "Bearer " + accessToken | ||
} | ||
}, | ||
function(err, resp, body) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
if (!/^2/.test("" + resp.statusCode)) { | ||
cb(body); | ||
return; | ||
} | ||
let parsedBody = JSON.parse(body); | ||
let profile = { | ||
user_id: parsedBody.staffId, | ||
nickname: parsedBody.name, | ||
name: parsedBody.name, | ||
email: parsedBody.username + "+" + parsedBody.activeCaseLoadId + "@nomis", | ||
username: parsedBody.username, | ||
blocked: !parsedBody.active, | ||
activeCaseLoadId: parsedBody.activeCaseLoadId, | ||
_nomisAccessToken: accessToken | ||
}; | ||
cb(null, profile); | ||
} | ||
); | ||
function fetchUserProfile(accessToken, context, callback) { | ||
// The email is only for auth0 usage purpose, not the actual email of login user | ||
const profile = { | ||
sub: context.sub, | ||
user_id: context.user_id, | ||
auth_source: context.auth_source, | ||
nickname: context.name, | ||
name: context.name, | ||
username: context.user_name, | ||
_accessToken: accessToken, | ||
email: context.user_name + "+" + context.user_id + "@" + context.auth_source, | ||
}; | ||
callback(null, profile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters