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: add OIDC Providers into UI #15

Merged
merged 4 commits into from
Mar 19, 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
14 changes: 10 additions & 4 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-03-14T15:15:04.384Z\n"
"PO-Revision-Date: 2024-03-14T15:15:04.384Z\n"
"POT-Creation-Date: 2024-03-18T18:33:20.852Z\n"
"PO-Revision-Date: 2024-03-18T18:33:20.852Z\n"

msgid "Please confirm that you are not a robot by checking the checkbox."
msgstr "Please confirm that you are not a robot by checking the checkbox."
Expand Down Expand Up @@ -92,6 +92,12 @@ msgstr "Creating account not available"
msgid "Contact a system administrator to create an account."
msgstr "Contact a system administrator to create an account."

msgid "Log in with Google"
msgstr "Log in with Google"

msgid "Log in with Microsoft"
msgstr "Log in with Microsoft"

msgid "Creating account not available"
msgstr "Creating account not available"

Expand Down Expand Up @@ -217,7 +223,7 @@ msgstr "Enter the new password for your account below"

msgid ""
"You should shortly be redirected. If you are not redirected, please click "
"button."
"redirect button."
msgstr ""
"You should shortly be redirected. If you are not redirected, please click "
"button."
"redirect button."
6 changes: 6 additions & 0 deletions i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ msgstr "Saisir un nouveau de passe"

msgid "Enter the new password for your account below"
msgstr "Saisir ci-dessous le nouveau de passe pour votre compte"

msgid "Log in with Google"
msgstr "Se connecter avec Google"

msgid "Log in with Microsoft"
msgstr "Se connecter avec Microsoft"
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export {
NotAllowedNoticeCreateAccount,
} from './not-allowed-notice.js'
export { Popup } from './pop-up.js'
export { OIDCLoginOptions } from './oidc-login-options.js'
52 changes: 52 additions & 0 deletions src/components/oidc-login-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import i18n from '@dhis2/d2-i18n'
import { Button } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import { useLoginConfig } from '../providers/index.js'
import styles from './oidc-login-options.module.css'

const loginTextStrings = {
login_with_google: i18n.t('Log in with Google'),
login_with_azure: i18n.t('Log in with Microsoft'),
}

const SVGIcon = ({ baseUrl, endpoint }) => (
<div>
<img height="24px" width="24px" src={`${baseUrl}${endpoint}`} />
</div>
)

SVGIcon.propTypes = {
baseUrl: PropTypes.string,
endpoint: PropTypes.string,
}

const redirectToOIDC = ({ baseUrl, endpoint }) => {
window.location.href = `${baseUrl}${endpoint}`
}

export const OIDCLoginOptions = () => {
const { oidcProviders, baseUrl, uiLocale } = useLoginConfig()
if (!(oidcProviders?.length > 0)) {
return null
}
return (
<div className={styles.formButtons}>
{oidcProviders.map((oidc) => (
<Button
icon={<SVGIcon baseUrl={baseUrl} endpoint={oidc?.icon} />}
key={oidc?.id}
onClick={() => {
redirectToOIDC({ baseUrl, endpoint: oidc?.url })
}}
>
{loginTextStrings[oidc?.loginText]
? i18n.t(loginTextStrings[oidc.loginText], {
lng: uiLocale,
})
: oidc?.loginText}
</Button>
))}
</div>
)
}
10 changes: 10 additions & 0 deletions src/components/oidc-login-options.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.formButtons {
display: flex;
flex-direction: var(--form-button-direction, column);
gap: var(--spacers-dp8);
margin-block: var(--spacers-dp16);
}

.formButtons * {
margin-block-start: '8px';
}
6 changes: 5 additions & 1 deletion src/pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FormNotice,
FormSubtitle,
LoginLinks,
OIDCLoginOptions,
} from '../components/index.js'
import { checkIsFormValid, getIsRequired } from '../helpers/index.js'
import { useLogin } from '../hooks/index.js'
Expand Down Expand Up @@ -260,7 +261,10 @@ const LoginFormContainer = () => {
uiLocale={uiLocale}
/>
{!twoFAVerificationRequired && (
<LoginLinks formUserName={formUserName} />
<>
<LoginLinks formUserName={formUserName} />
<OIDCLoginOptions />
</>
)}
</FormContainer>
)
Expand Down
Loading