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

move domain allowlist to Auth0 action #657

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Recidiviz - a data platform for criminal justice reform
// Copyright (C) 2020 Recidiviz, Inc.
// Copyright (C) 2024 Recidiviz, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -22,25 +22,25 @@
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePreUserRegistration = async (event, api) => {
const acceptedStateCodes = ["nd", "pa"];
const domainToStateCodeMap = {
"recidiviz.org": "recidiviz",
// add authorized domains here
// DO NOT COMMIT domains to version control
};

const emailSplit = event.user.email && event.user.email.split("@");
const userDomain = emailSplit?.[emailSplit.length - 1].toLowerCase();
if (userDomain) {
if (userDomain === "recidiviz.org") {
api.user.setAppMetadata("state_code", "recidiviz");
return;
}

/** 2. Add user's state_code to the app_metadata */
const domainSplit = userDomain.split(".");

// assumes the state is always the second to last component of the domain
// e.g. @doc.mo.gov or @nd.gov, but not @nd.docr.gov
const state = domainSplit[domainSplit.length - 2].toLowerCase();

if (acceptedStateCodes.includes(state)) {
const stateCode = `us_${state}`;
/** Add user's state_code to the app_metadata */
if (domainToStateCodeMap[userDomain]) {
const stateCode = domainToStateCodeMap[userDomain];
api.user.setAppMetadata("state_code", stateCode);
return;
}
}
// if we couldn't assign you a state code, you are not authorized
api.access.deny(
"email does not match list of approved domains",
"Access denied"
);
};

This file was deleted.

Loading