Skip to content

Commit

Permalink
fix(oidc): changes to fix build
Browse files Browse the repository at this point in the history
changes to fix build after merging with latest develop

re Fallenbagel#184
  • Loading branch information
sudopseudocode committed Sep 9, 2024
1 parent 2b7fee0 commit ae724d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
36 changes: 16 additions & 20 deletions server/utils/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
OidcTokenResponse,
} from '@server/interfaces/api/oidcInterfaces';
import { getSettings } from '@server/lib/settings';
import axios from 'axios';
import type { Request } from 'express';
import * as yup from 'yup';

Expand All @@ -16,13 +15,11 @@ export async function getOIDCWellknownConfiguration(domain: string) {
domain.replace(/\/$/, '') + '/.well-known/openid-configuration'
).toString();

const wellKnownInfo: OidcProviderMetadata = await axios
.get(wellKnownUrl, {
headers: {
'Content-Type': 'application/json',
},
})
.then((r) => r.data);
const wellKnownInfo: OidcProviderMetadata = await fetch(wellKnownUrl, {
headers: {
'Content-Type': 'application/json',
},
}).then((response) => response.json());

return wellKnownInfo;
}
Expand Down Expand Up @@ -68,24 +65,23 @@ export async function fetchOIDCTokenData(
formData.append('client_id', oidc.clientId);
formData.append('code', code);

return await axios
.post<OidcTokenResponse>(wellKnownInfo.token_endpoint, formData)
.then((r) => r.data);
return fetch(wellKnownInfo.token_endpoint, {
method: 'POST',
body: formData,
}).then((response) => response.json());
}

export async function getOIDCUserInfo(
wellKnownInfo: OidcProviderMetadata,
authToken: string
) {
const userInfo = await axios
.get(wellKnownInfo.userinfo_endpoint, {
headers: {
Authorization: `Bearer ${authToken}`,
Accept: 'application/json',
},
})
.then((r) => r.data);

const response = await fetch(wellKnownInfo.userinfo_endpoint, {
headers: {
Authorization: `Bearer ${authToken}`,
Accept: 'application/json',
},
});
const userInfo = await response.json();
return userInfo;
}

Expand Down
1 change: 0 additions & 1 deletion src/components/Login/ErrorCallout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Alert from '@app/components/Common/Alert';
import { Transition } from '@headlessui/react';
import type React from 'react';

interface LoginErrorProps {
error: string;
Expand Down
1 change: 0 additions & 1 deletion src/components/Login/OidcLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import useSettings from '@app/hooks/useSettings';
import globalMessages from '@app/i18n/globalMessages';
import OIDCAuth from '@app/utils/oidc';
import { ArrowLeftOnRectangleIcon } from '@heroicons/react/24/outline';
import type React from 'react';
import { useEffect } from 'react';
import { defineMessages, useIntl } from 'react-intl';

Expand Down
31 changes: 13 additions & 18 deletions src/utils/oidc.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import PopupWindow from '@app/utils/popupWindow';
import axios from 'axios';

export async function processCallback(params: URLSearchParams) {
return await axios
.get('/api/v1/auth/oidc-callback', { params })
.then((r) => ({
return fetch(`/api/v1/auth/oidc-callback?${new URLSearchParams(params)}`)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => ({
type: 'success',
message: r.data,
message: data,
}))
.catch((e) => {
if (e.response && e.response.data && e.response.data.message) {
return {
type: 'error',
message: e.response.data.message,
};
} else {
return {
type: 'error',
message: e.message,
};
}
});
.catch((error) => ({
type: 'error',
message: error.message || 'An error occurred',
}));
}

class OIDCAuth extends PopupWindow {
Expand Down

0 comments on commit ae724d4

Please sign in to comment.