Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPAT-1711 Change the userinfo js for nomis apps #1211

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion tests/api/test_auth0.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,13 @@ def _clean_string(content):
call_args, call_kwargs = call
actual_arg = call_args[0]

print(actual_arg["options"]["scripts"]["fetchUserProfile"])
ymao2 marked this conversation as resolved.
Show resolved Hide resolved
actual_arg["options"]["scripts"]["fetchUserProfile"] = _clean_string(
actual_arg["options"]["scripts"]["fetchUserProfile"]
)
expected["options"]["scripts"]["fetchUserProfile"] = _clean_string(
expected["options"]["scripts"]["fetchUserProfile"]
)

assert actual_arg == expected


Expand Down