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

feat(cb2-11450): allow system user to be forced for the user context #133

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all 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
18 changes: 18 additions & 0 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,25 @@ export const getUserDetails = (jwt: string): UserDetails => {
msOid: decodedToken.oid,
email: decodedToken.email ?? decodedToken.preferred_username ?? decodedToken.upn,
};

if (!userDetails?.username || !userDetails.msOid) {
// Data remediation requirements...
// If we have an authenticated token, but it is not running in the context of a user
// then it will be a client_credentials grant_type e.g. the data remediation app.
// In this scenario, this is a valid path, but the request is not running in the context of a user,
// so we don't have a username or email available in the token.
// To accommodate this, we can set an environment variable that allows for the username and email
// to be set to SYSTEM_USER.

// TODO: Can we replace this with custom claims in the Entra app registration. This way we can define
// 'client' (data remediation app) contact details for use here.
// TODO: The token dependency here should be refactored into the authorizer context object.
if (process.env.ENABLE_SYSTEM_USER_IMPERSONATION ?? false) {
userDetails.username = 'SYSTEM_USER';
userDetails.email = 'SYSTEM_USER';
return userDetails;
}

throw new Error(ERRORS.MISSING_USER_DETAILS);
}
return userDetails;
Expand Down
Loading