Skip to content

Commit

Permalink
DPAT-1711 Change the userinfo js for nomis apps (#1211)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
49 changes: 13 additions & 36 deletions controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js
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);
}
2 changes: 1 addition & 1 deletion tests/api/fixtures/nomis_body.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"options": {
"scripts": {
"fetchUserProfile": "function(accessToken, ctx, cb) {\n var base_url = \"https://testing.com\";\n var user_endpoint = \"/auth/api/user/me\";\n var user_profile_url = base_url + user_endpoint;\n\n // call oauth2 API with the accesstoken and create the profile\n request.get(\n user_profile_url, {\n headers: {\n Authorization: \"Bearer \" + accessToken\n }\n },\n function(err, resp, body) {\n if (err) {\n cb(err);\n return;\n }\n if (!/^2/.test(\"\" + resp.statusCode)) {\n cb(body);\n return;\n }\n let parsedBody = JSON.parse(body);\n let profile = {\n user_id: parsedBody.staffId,\n nickname: parsedBody.name,\n name: parsedBody.name,\n email: parsedBody.username + \"+\" + parsedBody.activeCaseLoadId + \"@nomis\",\n username: parsedBody.username,\n blocked: !parsedBody.active,\n activeCaseLoadId: parsedBody.activeCaseLoadId,\n _nomisAccessToken: accessToken\n };\n cb(null, profile);\n }\n );\n}"
"fetchUserProfile": "function fetchUserProfile(accessToken, context, callback) {\n // The email is only for auth0 usage purpose, not the actual email of login user\n const profile = {\n sub: context.sub,\n user_id: context.user_id,\n auth_source: context.auth_source,\n nickname: context.name,\n name: context.name,\n username: context.user_name,\n _accessToken: accessToken,\n email: context.user_name + \"+\" + context.user_id + \"@\" + context.auth_source,\n };\n callback(null, profile);\n}"
},
"client_id": "test_nomis_connection_id",
"client_secret": "WNXFkM3FCTXJhUWs0Q1NwcKFu",
Expand Down
1 change: 0 additions & 1 deletion tests/api/test_auth0.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ def _clean_string(content):
expected["options"]["scripts"]["fetchUserProfile"] = _clean_string(
expected["options"]["scripts"]["fetchUserProfile"]
)

assert actual_arg == expected


Expand Down

0 comments on commit 8fafe38

Please sign in to comment.