Skip to content
New issue

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

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

Already on GitHub? # to your account

CRDCDH-648 Replace AuthZ with core BE service #234

Merged
merged 1 commit into from
Dec 6, 2023
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
9 changes: 2 additions & 7 deletions nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ flowchart TD
id1["Nginx – port:4010"]
id2["FE – port:3010"]
id3["DEV Backend"]
id4["DEV AuthZ"]
id5["DEV AuthN"]

id0 <--"https://localhost:4010"--> id1
Expand All @@ -71,8 +70,8 @@ flowchart TD
end
subgraph be["DEV/DEV2 Hosted Backend Services"]
id1 --"/api/graphql"---> id3
id1 --"/api/authn/"---> id4
id1 --"/api/authz/"---> id5
id1 --"/api/authz/"---> id3
id1 --"/api/authn/"---> id5
end
subgraph fe["Frontend Services"]
id2
Expand All @@ -87,7 +86,6 @@ An overview of the local deployment architecture is shown below using the follow

- Frontend – <https://github.com/CBIIT/crdc-datahub-ui>
- Backend – <https://github.com/CBIIT/crdc-datahub-backend>
- AuthZ – <https://github.com/CBIIT/crdc-datahub-authz>
- AuthN – <https://github.com/CBIIT/crdc-datahub-authn>
- MongoDB

Expand All @@ -102,7 +100,6 @@ flowchart TD
id1["Nginx – port:4010"]
id2["FE – port:3010"]
id3["BE – port:4020"]
id4["AuthZ – port:4030"]
id5["AuthN – port:4040"]
id6["MongoDB"]

Expand All @@ -117,13 +114,11 @@ flowchart TD
subgraph be["Backend Services"]
direction RL
id3
id4
id5
subgraph misc["Misc. Dependencies"]
id6
end
id3-->misc
id4-->misc
id5-->misc
end
subgraph fe["Frontend Services"]
Expand Down
6 changes: 3 additions & 3 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ http {
proxy_pass "https://hub-dev2.datacommons.cancer.gov/api/authn/";
}

# AuthZ
# AuthZ (NOTE: This is legacy and is now handled by the backend)
location /api/authz/ {
# proxy_pass http://localhost:4020/api/authz/;
proxy_pass "https://hub-dev2.datacommons.cancer.gov/api/authz/";
# proxy_pass http://localhost:4020/api/;
proxy_pass "https://hub-dev2.datacommons.cancer.gov/api/";
}

# Backend
Expand Down
22 changes: 3 additions & 19 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
import {
ApolloClient, InMemoryCache, ApolloLink, HttpLink, DefaultOptions
} from '@apollo/client';
Expand All @@ -10,21 +9,12 @@ const defaultOptions:DefaultOptions = {
},
};

const BACKEND = env.REACT_APP_BACKEND_API;
const MOCK = 'https://7a242248-52f7-476a-a60f-d64a2db3dd5b.mock.pstmn.io/graphql';
const USER_SERVICE = `${window.origin}/api/authz/graphql`;

const backendService = new HttpLink({
uri: BACKEND,
});

const userService = new HttpLink({
uri: USER_SERVICE,
uri: env.REACT_APP_BACKEND_API,
});


const mockService = new HttpLink({
uri: MOCK,
uri: "https://7a242248-52f7-476a-a60f-d64a2db3dd5b.mock.pstmn.io/graphql",
headers: {
'x-mock-match-request-body': 'true',
},
Expand All @@ -36,14 +26,8 @@ const client = new ApolloClient({
link: ApolloLink.split(
(operation) => operation.getContext().clientName === 'mockService',
mockService,
ApolloLink.split(
(operation) => operation.getContext().clientName === 'userService',
// the string "userService" can be anything you want,
userService, // <= apollo will send to this if clientName is "userService"
backendService, // <= otherwise will send to this
), // <= otherwise will send to this
backendService
),
});


export default client;
4 changes: 2 additions & 2 deletions src/components/Contexts/AuthContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("AuthContext > AuthProvider Tests", () => {
expect(screen.getByTestId("last-name").textContent).toEqual(userData.lastName);
});

it("should successfully verify the cached user with the AuthZ service", async () => {
it("should successfully verify the cached user with the BE service", async () => {
const userData = {
_id: "123-random-id-456",
firstName: "Random",
Expand Down Expand Up @@ -151,7 +151,7 @@ describe("AuthContext > AuthProvider Tests", () => {
expect(cachedUser.firstName).toEqual("The API updated my first name");
});

it("should logout the user if the AuthZ API call fails", async () => {
it("should logout the user if the BE API call fails", async () => {
const userData = {
_id: "GGGG-1393-AAA-9101",
firstName: "Random",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const AuthProvider: FC<ProviderProps> = ({ children } : ProviderProps) =>
const [state, setState] = useState<ContextState>(cachedState || initialState);

const [getMyUser] = useLazyQuery<GetUserResp>(GET_USER, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache',
});

Expand Down Expand Up @@ -156,7 +156,7 @@ export const AuthProvider: FC<ProviderProps> = ({ children } : ProviderProps) =>

useEffect(() => {
(async () => {
// User had an active session, reverify with AuthZ
// User had an active session, reverify with BE
if (cachedState) {
const { data, error } = await getMyUser();
if (error || !data?.getMyUser) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Contexts/OrganizationListContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const OrganizationProvider: FC<ProviderProps> = ({ preload, filterInactiv
const [state, setState] = useState<ContextState>(initialState);

const { data, loading, error } = preload ? useQuery<ListOrgsResp>(LIST_ORGS, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
}) : { data: null, loading: false, error: null };

Expand Down
2 changes: 1 addition & 1 deletion src/content/dataSubmissions/DataSubmissionsListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const ListingView: FC = () => {
const { data: allOrganizations } = useQuery<listOrganizationsResponse>(listOrganizationsQuery, {
variables: {
},
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: "no-cache",
});

Expand Down
8 changes: 4 additions & 4 deletions src/content/organizations/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {
];

const { data: activeCurators } = useQuery<ListCuratorsResp>(LIST_CURATORS, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: "no-cache",
});

Expand All @@ -175,17 +175,17 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {
});

const [getOrganization] = useLazyQuery<GetOrgResp>(GET_ORG, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

const [editOrganization] = useMutation<EditOrgResp>(EDIT_ORG, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

const [createOrganization] = useMutation<CreateOrgResp>(CREATE_ORG, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

Expand Down
2 changes: 1 addition & 1 deletion src/content/users/APITokenDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const APITokenDialog: FC<Props> = ({
const [changesAlert, setChangesAlert] = useState<AlertState>(null);

const [grantToken] = useMutation<GrantTokenResp>(GRANT_TOKEN, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

Expand Down
2 changes: 1 addition & 1 deletion src/content/users/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const ListingView: FC = () => {
const statusFilter = watch("status");

const { data, loading, error } = useQuery<ListUsersResp>(LIST_USERS, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: "no-cache",
});

Expand Down
6 changes: 3 additions & 3 deletions src/content/users/ProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
const fieldset = useMemo(() => getEditableFields(currentUser, user, viewType), [user?._id, _id, currentUser?.role, viewType]);

const [getUser] = useLazyQuery<GetUserResp>(GET_USER, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

const [updateMyUser] = useMutation<UpdateMyUserResp, { userInfo: UserInput }>(UPDATE_MY_USER, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

const [editUser] = useMutation<EditUserResp>(EDIT_USER, {
context: { clientName: 'userService' },
context: { clientName: 'backend' },
fetchPolicy: 'no-cache'
});

Expand Down