diff --git a/controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js b/controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js index df80b7688..edd73a7ca 100644 --- a/controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js +++ b/controlpanel/api/auth0_conns/auth0_nomis/fetchUserProfile.js @@ -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); } diff --git a/tests/api/fixtures/nomis_body.json b/tests/api/fixtures/nomis_body.json index 17a598b0c..084d06dbd 100644 --- a/tests/api/fixtures/nomis_body.json +++ b/tests/api/fixtures/nomis_body.json @@ -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", diff --git a/tests/api/test_auth0.py b/tests/api/test_auth0.py index 00c00a4cf..3d6695c70 100644 --- a/tests/api/test_auth0.py +++ b/tests/api/test_auth0.py @@ -600,7 +600,6 @@ def _clean_string(content): expected["options"]["scripts"]["fetchUserProfile"] = _clean_string( expected["options"]["scripts"]["fetchUserProfile"] ) - assert actual_arg == expected