diff --git a/CLAUDE.md b/CLAUDE.md index 45d0ce4947..99c7a25555 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -168,10 +168,7 @@ return

{t('Dashboard')}

; ## Authentication & Environment -The app supports two auth providers via `AUTH_PROVIDER` env var: - -- `OKTA` (default) - requires `OKTA_*` variables -- `API_OAUTH` - requires `API_OAUTH_*` variables +The app signs in with Okta (`AUTH_PROVIDER=OKTA`), which requires the `OKTA_*` variables. Critical environment setup: diff --git a/README.md b/README.md index b62819d680..56296fc58b 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Note: there is a test account you can use. Get this from another developer if yo ### Cru specific secrets -- `AUTH_PROVIDER` - Name of auth provider used in application. Set to `OKTA` or `API_OAUTH` +- `AUTH_PROVIDER` - Name of auth provider used in application. Set to `OKTA` - `ROLLBAR_ACCESS_TOKEN` - Optional token for sending error reports to Rollbar - `ROLLBAR_SERVER_ACCESS_TOKEN` - Optional token for sending error reports on server pages to Rollbar - `CROWDIN_API_TOKEN` - Secret key for uploading/downloading translations from CrowdIn @@ -118,32 +118,19 @@ Note: there is a test account you can use. Get this from another developer if yo #### Auth provider -MPDX has two auth providers, Okta (which is default) and our own API OAuth. You'll need to configure one. +MPDX signs in with Okta. You'll need to configure it. ``` AUTH_PROVIDER=OKTA ``` -AUTH_PROVIDER can be changed to the following auth providers options: `OKTA` or `API_OAUTH`. - -If you choose `OKTA`, you will also need to configure these environment variables. +You will also need to configure these environment variables. - `OKTA_CLIENT_ID` - Okta Client ID for your Okta account - `OKTA_CLIENT_SECRET` - Okta Client secret for your Okta account - `OKTA_ISSUER` - Okta issuer web address - `OKTA_SIGNOUT_REDIRECT_URL` - URL to send user after successful logout. Must match Default App Sign-In Custom Url on Okta's settings. -If you choose `API_OAUTH`, you will need to configure these environment variables. - -- `API_OAUTH_CLIENT_ID` - Api OAuth Client ID -- `API_OAUTH_CLIENT_SECRET` - Api OAuth Client Secret -- `API_OAUTH_ISSUER_AUTHORIZATION_URL` - Api OAuth issuer authorization url -- `API_OAUTH_ISSUER_TOKEN_URL` - Api OAuth issuer token url -- `API_OAUTH_SCOPE` - Scope for Api OAuth -- `API_OAUTH_VISIBLE_NAME` - UI name for your OAuth, default is `SSO`. - -_Also if you're viewing the next-auth code, you'll come across this file `pages/api/auth/apiOauthSignIn.ts`. `apiOauthSignIn.ts` is a Graphql generated file, but since the apiOauthSignIn Graphql isn't added to MPDX API Prod, only to MPDX API Staging for security reasons. We've added the generated file for apiOauthSignIn and not the GraphQl file since it will cause build errors on prod._ - #### Favicon & Logo Env Vars Since we don't want accidental re-use of our logos by non-Cru organizations, the values of `NEXT_PUBLIC_MEDIA_LOGO` and `NEXT_PUBLIC_MEDIA_FAVICON` are not included in this README. diff --git a/next.config.ts b/next.config.ts index c17cbbce5b..c7c99f5bb0 100644 --- a/next.config.ts +++ b/next.config.ts @@ -8,9 +8,6 @@ if (process.env.secrets && process.env.secrets !== '{}') { process.env.OKTA_CLIENT_SECRET = JSON.parse( process.env.secrets, ).OKTA_CLIENT_SECRET; - process.env.API_OAUTH_CLIENT_SECRET = JSON.parse( - process.env.secrets, - ).API_OAUTH_CLIENT_SECRET; process.env.ROLLBAR_SERVER_ACCESS_TOKEN = JSON.parse( process.env.secrets, ).ROLLBAR_SERVER_ACCESS_TOKEN; @@ -43,18 +40,6 @@ const config: NextConfig = { OKTA_ISSUER: process.env.OKTA_ISSUER ?? 'https://signon.okta.com', OKTA_SIGNOUT_REDIRECT_URL: process.env.OKTA_SIGNOUT_REDIRECT_URL ?? 'http://localhost:3000', - API_OAUTH_CLIENT_ID: - process.env.API_OAUTH_CLIENT_ID ?? - '3nxoth_gyetHdpjKp2WYkND1PUQlvYcjXQHW9ZdDxq4', - API_OAUTH_CLIENT_SECRET: process.env.API_OAUTH_CLIENT_SECRET, - API_OAUTH_ISSUER_AUTHORIZATION_URL: - process.env.API_OAUTH_ISSUER_AUTHORIZATION_URL ?? - 'https://api.stage.mpdx.org/oauth/authorize', - API_OAUTH_ISSUER_TOKEN_URL: - process.env.API_OAUTH_ISSUER_TOKEN_URL ?? - 'https://api.stage.mpdx.org/oauth/token', - API_OAUTH_SCOPE: process.env.API_OAUTH_SCOPE ?? 'read write', - API_OAUTH_VISIBLE_NAME: process.env.API_OAUTH_VISIBLE_NAME ?? 'SSO', GOOGLE_MAPS_API_KEY: process.env.GOOGLE_MAPS_API_KEY, GOOGLE_TAG_MANAGER_CONTAINER_ID: process.env.GOOGLE_TAG_MANAGER_CONTAINER_ID, diff --git a/pages/api/auth/[...nextauth].page.test.ts b/pages/api/auth/[...nextauth].page.test.ts new file mode 100644 index 0000000000..942fabdf71 --- /dev/null +++ b/pages/api/auth/[...nextauth].page.test.ts @@ -0,0 +1,82 @@ +// The real next-auth pulls in ESM-only dependencies that Jest cannot load, and the guards run +// before either export is used +jest.mock('next-auth', () => jest.fn()); +jest.mock('next-auth/providers/okta', () => jest.fn(() => ({ id: 'okta' }))); + +describe('NextAuth startup guards', () => { + const originalEnv = process.env; + + const loadAuth = () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires + require('./[...nextauth].page'); + }; + + beforeEach(() => { + jest.resetModules(); + process.env = { + ...originalEnv, + AUTH_PROVIDER: 'OKTA', + OKTA_CLIENT_ID: 'okta-client-id', + OKTA_CLIENT_SECRET: 'okta-client-secret', + OKTA_ISSUER: 'https://example.okta.com', + }; + }); + + afterAll(() => { + process.env = originalEnv; + }); + + it('loads when AUTH_PROVIDER is OKTA and the Okta envs are set', () => { + expect(loadAuth).not.toThrow(); + }); + + it.each(['API_OAUTH', 'okta', '', undefined])( + 'throws when AUTH_PROVIDER is %p', + (authProvider) => { + process.env.AUTH_PROVIDER = authProvider; + + expect(loadAuth).toThrow( + 'AUTH_PROVIDER environment variable needs to equal "OKTA"', + ); + }, + ); + + it.each(['OKTA_CLIENT_ID', 'OKTA_CLIENT_SECRET', 'OKTA_ISSUER'])( + 'throws when %s is missing', + (envName) => { + delete process.env[envName]; + + expect(loadAuth).toThrow( + 'OKTA_CLIENT_ID, OKTA_CLIENT_SECRET or OKTA_ISSUER envs not defined', + ); + }, + ); + + describe('options', () => { + const getOptions = () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { default: Auth } = require('./[...nextauth].page'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const NextAuth = require('next-auth') as jest.Mock; + Auth({}, {}); + return NextAuth.mock.calls[0][2]; + }; + + it('configures only the Okta provider', () => { + expect(getOptions().providers).toEqual([{ id: 'okta' }]); + }); + + it('sends sign out to the Okta sign-out URL', () => { + process.env.OKTA_SIGNOUT_REDIRECT_URL = 'https://mpdx.org/login'; + + expect( + getOptions().callbacks.redirect({ + url: 'signOut', + baseUrl: 'https://mpdx.org', + }), + ).toBe( + 'https://signon.okta.com/login/signout?fromURI=https%3A%2F%2Fmpdx.org%2Flogin', + ); + }); + }); +}); diff --git a/pages/api/auth/[...nextauth].page.ts b/pages/api/auth/[...nextauth].page.ts index 1a5efabe24..c7dd624ae1 100644 --- a/pages/api/auth/[...nextauth].page.ts +++ b/pages/api/auth/[...nextauth].page.ts @@ -8,11 +8,6 @@ import { GetUserAccessQueryVariables, } from 'src/components/Shared/MultiPageLayout/MultiPageMenu/MultiPageMenuItems.generated'; import makeSsrClient from 'src/lib/apollo/ssrClient'; -import { - ApiOauthSignInDocument, - ApiOauthSignInMutation, - ApiOauthSignInMutationVariables, -} from './apiOauthSignIn'; import { isJwtExpired, setUserInfo } from './helpers'; import { OktaSignInDocument, @@ -59,96 +54,28 @@ declare module 'next-auth/jwt' { const AUTH_PROVIDER = process.env.AUTH_PROVIDER, OKTA_CLIENT_ID = process.env.OKTA_CLIENT_ID, OKTA_CLIENT_SECRET = process.env.OKTA_CLIENT_SECRET, - OKTA_ISSUER = process.env.OKTA_ISSUER, - API_OAUTH_CLIENT_ID = process.env.API_OAUTH_CLIENT_ID, - API_OAUTH_CLIENT_SECRET = process.env.API_OAUTH_CLIENT_SECRET, - API_OAUTH_ISSUER_AUTHORIZATION_URL = - process.env.API_OAUTH_ISSUER_AUTHORIZATION_URL, - API_OAUTH_ISSUER_TOKEN_URL = process.env.API_OAUTH_ISSUER_TOKEN_URL, - API_OAUTH_SCOPE = process.env.API_OAUTH_SCOPE; + OKTA_ISSUER = process.env.OKTA_ISSUER; -if (AUTH_PROVIDER !== 'OKTA' && AUTH_PROVIDER !== 'API_OAUTH') { - throw new Error( - 'AUTH_PROVIDER environment variable needs to equal either "OKTA" or "API_OAUTH"', - ); +if (AUTH_PROVIDER !== 'OKTA') { + throw new Error('AUTH_PROVIDER environment variable needs to equal "OKTA"'); } -if ( - AUTH_PROVIDER === 'OKTA' && - (!OKTA_CLIENT_ID || !OKTA_CLIENT_SECRET || !OKTA_ISSUER) -) { +if (!OKTA_CLIENT_ID || !OKTA_CLIENT_SECRET || !OKTA_ISSUER) { throw new Error( 'OKTA_CLIENT_ID, OKTA_CLIENT_SECRET or OKTA_ISSUER envs not defined', ); } -if ( - AUTH_PROVIDER === 'API_OAUTH' && - (!API_OAUTH_CLIENT_ID || - !API_OAUTH_CLIENT_SECRET || - !API_OAUTH_ISSUER_AUTHORIZATION_URL || - !API_OAUTH_ISSUER_TOKEN_URL || - !API_OAUTH_SCOPE) -) { - throw new Error( - 'API_OAUTH_CLIENT_ID, API_OAUTH_CLIENT_SECRET, API_OAUTH_ISSUER_AUTHORIZATION_URL, API_OAUTH_ISSUER_TOKEN_URL or API_OAUTH_SCOPE envs not defined', - ); -} -const providersArray: NextAuthOptions['providers'] = []; - -if (AUTH_PROVIDER === 'OKTA') { - providersArray.push( - OktaProvider({ - clientId: OKTA_CLIENT_ID ?? '', - clientSecret: OKTA_CLIENT_SECRET ?? '', - issuer: OKTA_ISSUER ?? '', - authorization: { params: { scope: 'openid email profile' } }, - token: { params: { scope: 'openid email profile' } }, - userinfo: { params: { scope: 'openid email profile' } }, - }), - ); -} - -if (AUTH_PROVIDER === 'API_OAUTH') { - providersArray.push({ - id: 'apioauth', - name: process.env.API_OAUTH_VISIBLE_NAME ?? 'SSO', - type: 'oauth', - clientId: API_OAUTH_CLIENT_ID ?? '', - clientSecret: API_OAUTH_CLIENT_SECRET ?? '', - authorization: { - url: API_OAUTH_ISSUER_AUTHORIZATION_URL ?? '', - params: { scope: API_OAUTH_SCOPE ?? '', response_type: 'code' }, - }, - token: { - url: API_OAUTH_ISSUER_TOKEN_URL ?? '', - params: { scope: API_OAUTH_SCOPE ?? '', response_type: 'code' }, - }, - userinfo: { - async request() { - // Our API doesn't use the auth/userInfo endpoint, but NextAuth requires it to get the access token. - // Since we pass the access_token to our API, which returns a JWT, user and authenticates via GraphQL - // We can just return a object with hardcoded info, as it doesn't get used anywhere. - return { - sub: '83692', - name: 'Alice Adams', - given_name: 'Alice', - family_name: 'Adams', - email: 'alice.adams@gmail.cpm', - picture: 'https://example.com/83692/photo.jpg', - }; - }, - }, - idToken: false, - profile(profile) { - return { - id: profile?.sub, - email: profile?.email, - }; - }, - checks: ['pkce', 'state'], - }); -} +const providersArray: NextAuthOptions['providers'] = [ + OktaProvider({ + clientId: OKTA_CLIENT_ID ?? '', + clientSecret: OKTA_CLIENT_SECRET ?? '', + issuer: OKTA_ISSUER ?? '', + authorization: { params: { scope: 'openid email profile' } }, + token: { params: { scope: 'openid email profile' } }, + userinfo: { params: { scope: 'openid email profile' } }, + }), +]; const Auth = (req: NextApiRequest, res: NextApiResponse): Promise => { const options: NextAuthOptions = { @@ -184,30 +111,9 @@ const Auth = (req: NextApiRequest, res: NextApiResponse): Promise => { } }; - // An API token is not required for the apiOauthSignIn or oktaSignIn mutations + // An API token is not required for the oktaSignIn mutation const ssrClient = makeSsrClient(null); - if (account.provider === 'apioauth') { - const { data } = await ssrClient.mutate< - ApiOauthSignInMutation, - ApiOauthSignInMutationVariables - >({ - mutation: ApiOauthSignInDocument, - variables: { - accessToken: access_token, - }, - }); - - if (data?.apiOauthSignIn?.token && data?.apiOauthSignIn?.user) { - await handleSettingUserInfo( - data.apiOauthSignIn.token, - data.apiOauthSignIn.user.id, - ); - return true; - } - throw new Error('apiOauthSignIn mutation failed to return a token'); - } - const { data } = await ssrClient.mutate< OktaSignInMutation, OktaSignInMutationVariables @@ -284,7 +190,7 @@ const Auth = (req: NextApiRequest, res: NextApiResponse): Promise => { if (url.startsWith(baseUrl)) { return url; } - if (url === 'signOut' && AUTH_PROVIDER === 'OKTA') { + if (url === 'signOut') { return `https://signon.okta.com/login/signout?fromURI=${encodeURIComponent( process.env.OKTA_SIGNOUT_REDIRECT_URL ?? '', )}`; diff --git a/pages/api/auth/apiOauthSignIn.ts b/pages/api/auth/apiOauthSignIn.ts deleted file mode 100644 index da58f63f15..0000000000 --- a/pages/api/auth/apiOauthSignIn.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* eslint-disable */ -import type * as Types from 'src/graphql/types.generated'; -import { gql, useMutation } from '@apollo/client'; -import type * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type ApiOauthSignInMutationVariables = Types.Exact<{ - accessToken: Types.Scalars['String']['input']; -}>; - -type ApiOauthSignInMutationPayload = { - __typename?: 'ApiOauthSignInMutationPayload'; - /** A unique identifier for the client performing the mutation. */ - clientMutationId?: Types.Maybe; - token?: Types.Maybe; - user?: Types.Maybe; -}; - -// Graphql apiOauthSignIn is not added to MPDX API Prod, only to MPDX API Staging for security reasons. -// We've added the generated file for apiOauthSignIn and not the GraphQl file since it will cause build errors on prod. - -export type ApiOauthSignInMutation = { __typename?: 'Mutation' } & { - apiOauthSignIn?: Types.Maybe< - { __typename?: 'ApiOauthSignInMutationPayload' } & Pick< - ApiOauthSignInMutationPayload, - 'token' - > & { - user?: Types.Maybe< - { __typename?: 'User' } & Pick & { - name: Types.User['firstName']; - } - >; - } - >; -}; - -export const ApiOauthSignInDocument = gql` - mutation apiOauthSignIn($accessToken: String!) { - apiOauthSignIn(input: { accessToken: $accessToken }) { - token - user { - id - name: firstName - } - } - } -`; -export type ApiOauthSignInMutationFn = Apollo.MutationFunction< - ApiOauthSignInMutation, - ApiOauthSignInMutationVariables ->; - -/** - * __useApiOauthSignInMutation__ - * - * To run a mutation, you first call `useApiOauthSignInMutation` within a React component and pass it any options that fit your needs. - * When your component renders, `useApiOauthSignInMutation` returns a tuple that includes: - * - A mutate function that you can call at any time to execute the mutation - * - An object with fields that represent the current status of the mutation's execution - * - * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; - * - * @example - * const [apiOauthSignInMutation, { data, loading, error }] = useApiOauthSignInMutation({ - * variables: { - * accessToken: // value for 'accessToken' - * }, - * }); - */ -export function useApiOauthSignInMutation( - baseOptions?: Apollo.MutationHookOptions< - ApiOauthSignInMutation, - ApiOauthSignInMutationVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return useMutation( - ApiOauthSignInDocument, - options, - ); -} -export type ApiOauthSignInMutationHookResult = ReturnType< - typeof useApiOauthSignInMutation ->; -export type ApiOauthSignInMutationResult = - Apollo.MutationResult; -export type ApiOauthSignInMutationOptions = Apollo.BaseMutationOptions< - ApiOauthSignInMutation, - ApiOauthSignInMutationVariables ->; diff --git a/pages/login-apioauth.page.test.tsx b/pages/login-apioauth.page.test.tsx deleted file mode 100644 index 1af31e9877..0000000000 --- a/pages/login-apioauth.page.test.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import { GetServerSidePropsContext } from 'next'; -import { ThemeProvider } from '@mui/material/styles'; -import { render, waitFor } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { getSession, signIn } from 'next-auth/react'; -import TestRouter from '__tests__/util/TestRouter'; -import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; -import theme from 'src/theme'; -import Login, { LoginProps, getServerSideProps } from './login.page'; - -jest.mock('next-auth/react', () => ({ - getSession: jest.fn(), - signIn: jest.fn(), -})); - -interface GetServerSidePropsReturn { - props: LoginProps; - redirect: unknown; -} - -interface ComponentsProps { - props: LoginProps; - mutationSpy?: () => void; -} - -const Components = ({ props, mutationSpy }: ComponentsProps) => ( - - - - - - - -); - -describe('Login - API_OAUTH', () => { - const setHeaderMock = jest.fn(); - const context = { - query: { - accountListId: 'accountListId', - }, - res: { - setHeader: setHeaderMock, - }, - req: { - headers: { - cookie: '', - }, - }, - } as unknown as GetServerSidePropsContext; - - beforeEach(() => { - setHeaderMock.mockClear(); - }); - - process.env.AUTH_PROVIDER = 'API_OAUTH'; - process.env.API_OAUTH_VISIBLE_NAME = 'Third-party oAuth'; - - it('should pass down props and render login', async () => { - (getSession as jest.Mock).mockResolvedValue(null); - const { props, redirect } = (await getServerSideProps( - context, - )) as GetServerSidePropsReturn; - - expect(props).toEqual({ - signInAuthProviderId: 'apioauth', - immediateSignIn: false, - isOkta: false, - }); - expect(redirect).toBeUndefined(); - - const { getByRole } = render(); - - expect( - getByRole('button', { name: 'Sign In with Third-party oAuth' }), - ).toBeInTheDocument(); - }); - - it('should immediate Sign In if cookie present', async () => { - context.req.headers.cookie = - 'cookieOne=valueOne;mpdx-handoff.redirect-url=http://URL.org;cookieTwo=valueTwo;'; - const { props, redirect } = (await getServerSideProps( - context, - )) as GetServerSidePropsReturn; - - expect(props).toEqual({ - signInAuthProviderId: 'apioauth', - immediateSignIn: true, - isOkta: false, - }); - expect(redirect).toBeUndefined(); - expect(setHeaderMock).toHaveBeenCalledWith( - 'Set-Cookie', - `mpdx-handoff.redirect-url=; HttpOnly; path=/; Max-Age=0`, - ); - - const { getByTestId } = render(); - - await waitFor(() => expect(getByTestId('Loading')).toBeInTheDocument()); - expect(signIn).toHaveBeenCalledWith('apioauth'); - }); - - it('calls signin on button click', async () => { - context.req.headers.cookie = ''; - const { props } = (await getServerSideProps( - context, - )) as GetServerSidePropsReturn; - - const { queryByTestId, getByRole } = render(); - - await waitFor(() => - expect(queryByTestId('Loading')).not.toBeInTheDocument(), - ); - - const loginButton = getByRole('button', { - name: /sign in/i, - }); - await waitFor(() => expect(loginButton).toBeInTheDocument()); - userEvent.click(loginButton); - - await waitFor(() => { - expect(signIn).toHaveBeenCalledTimes(1); - expect(signIn).toHaveBeenCalledWith('apioauth'); - }); - }); - - it('does not render create account help text', () => { - const { queryByText } = render( - , - ); - - expect(queryByText(/Don't have an Okta account\?/)).not.toBeInTheDocument(); - }); -}); diff --git a/pages/login.page.test.tsx b/pages/login.page.test.tsx index 1c98adc480..f38768f8fc 100644 --- a/pages/login.page.test.tsx +++ b/pages/login.page.test.tsx @@ -35,7 +35,6 @@ const Components = ({ props, mutationSpy }: ComponentsProps) => ( ); describe('Login - OKTA', () => { - process.env.AUTH_PROVIDER = 'OKTA'; const setHeaderMock = jest.fn(); const context = { query: { @@ -83,9 +82,7 @@ describe('Login - OKTA', () => { )) as GetServerSidePropsReturn; expect(props).toEqual({ - signInAuthProviderId: 'okta', immediateSignIn: false, - isOkta: true, }); expect(redirect).toBeUndefined(); }); @@ -102,9 +99,7 @@ describe('Login - OKTA', () => { )) as GetServerSidePropsReturn; expect(props).toEqual({ - signInAuthProviderId: 'okta', immediateSignIn: false, - isOkta: true, }); expect(redirect).toBeUndefined(); }); @@ -117,9 +112,7 @@ describe('Login - OKTA', () => { )) as GetServerSidePropsReturn; expect(props).toEqual({ - signInAuthProviderId: 'okta', immediateSignIn: true, - isOkta: true, }); expect(redirect).toBeUndefined(); expect(setHeaderMock).toHaveBeenCalledWith( @@ -145,9 +138,7 @@ describe('Login - OKTA', () => { expect(queryByTestId('Loading')).not.toBeInTheDocument(), ); - const loginButton = getByRole('button', { - name: /sign in/i, - }); + const loginButton = getByRole('button', { name: 'Sign In' }); await waitFor(() => expect(loginButton).toBeInTheDocument()); userEvent.click(loginButton); @@ -179,9 +170,7 @@ describe('Login - OKTA', () => { const { getByText } = render( , ); diff --git a/pages/login.page.tsx b/pages/login.page.tsx index 716f2b5a87..75a0c5c1e5 100644 --- a/pages/login.page.tsx +++ b/pages/login.page.tsx @@ -18,28 +18,20 @@ const SignUpBox = styled('div')(({ theme }) => ({ })); export interface LoginProps { - signInAuthProviderId: string; immediateSignIn: boolean; - isOkta: boolean; } -const Login = ({ - signInAuthProviderId, - immediateSignIn, - isOkta, -}: LoginProps): ReactElement => { +const OKTA_PROVIDER_ID = 'okta'; + +const Login = ({ immediateSignIn }: LoginProps): ReactElement => { const { t } = useTranslation(); const appName = getAppName(); - const signInButtonText = isOkta - ? t('Sign In') - : t('Sign In with {{authProviderName}}', { - authProviderName: process.env.API_OAUTH_VISIBLE_NAME, - }); + const signInButtonText = t('Sign In'); useEffect(() => { if (immediateSignIn) { - signIn(signInAuthProviderId); + signIn(OKTA_PROVIDER_ID); } }, []); @@ -68,7 +60,7 @@ const Login = ({ id="sign-in-button" size="large" variant="contained" - onClick={() => signIn(signInAuthProviderId)} + onClick={() => signIn(OKTA_PROVIDER_ID)} color="inherit" > {signInButtonText} @@ -85,16 +77,14 @@ const Login = ({ Find help )} - {isOkta && ( - - - Don't have an Okta account? -
- Click the Sign in button above, then{' '} - Sign up. -
-
- )} + + + Don't have an Okta account? +
+ Click the Sign in button above, then{' '} + Sign up. +
+
); @@ -104,9 +94,6 @@ Login.layout = BaseLayout; export const getServerSideProps: GetServerSideProps = async (context) => { const session = await getSession(context); - const authProvider = process.env.AUTH_PROVIDER; - - const signInAuthProviderId = authProvider?.toLowerCase()?.replace(/_/g, ''); const redirectCookie = extractCookie( context.req.headers?.cookie, @@ -136,9 +123,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { return { props: { - signInAuthProviderId, immediateSignIn, - isOkta: authProvider === 'OKTA', }, }; };