-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,602 additions
and
282 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { UpdateSSOProviderRequest } from '@theniledev/browser'; | ||
|
||
import SimpleForm from '../lib/SimpleForm'; | ||
import { useApi } from '../context'; | ||
import { Attribute, AttributeType } from '../lib/SimpleForm/types'; | ||
|
||
import { Props } from './types'; | ||
|
||
export default function BaseSSOForm(props: Props & { providerName: string }) { | ||
const api = useApi(); | ||
const { config, providerName, onSuccess, onError, allowEdit = true } = props; | ||
const attributes = React.useMemo(() => { | ||
const attributes: Attribute[] = [ | ||
{ | ||
name: 'clientId', | ||
label: 'Client id', | ||
type: AttributeType.Text, | ||
defaultValue: config?.clientId ?? '', | ||
required: true, | ||
disabled: !allowEdit, | ||
}, | ||
{ | ||
name: 'configUrl', | ||
label: 'Config url', | ||
type: AttributeType.Text, | ||
defaultValue: config?.configUrl ?? '', | ||
required: true, | ||
disabled: !allowEdit, | ||
}, | ||
{ | ||
name: 'redirectURI', | ||
label: 'Redirect URI', | ||
type: AttributeType.Text, | ||
helpText: 'Where users should be redirected to upon login', | ||
defaultValue: config?.redirectURI ?? '', | ||
required: true, | ||
disabled: !allowEdit, | ||
}, | ||
{ | ||
name: 'emailDomains', | ||
label: 'Email domains', | ||
type: AttributeType.Text, | ||
defaultValue: config?.emailDomains?.join(', ') ?? '', | ||
required: true, | ||
helpText: 'A comma seperated list of email domains to be used', | ||
disabled: !allowEdit, | ||
}, | ||
]; | ||
if (!config?.clientId) { | ||
attributes.splice(1, 0, { | ||
name: 'clientSecret', | ||
label: 'Client secret', | ||
type: AttributeType.Text, | ||
defaultValue: '', | ||
required: true, | ||
disabled: !allowEdit, | ||
}); | ||
} | ||
return attributes; | ||
}, [ | ||
allowEdit, | ||
config?.clientId, | ||
config?.configUrl, | ||
config?.emailDomains, | ||
config?.redirectURI, | ||
]); | ||
|
||
const mutation = useMutation( | ||
(ssoRequest: UpdateSSOProviderRequest) => { | ||
return api.auth.updateSSOProvider({ | ||
providerName: providerName.toLowerCase(), | ||
updateSSOProviderRequest: ssoRequest, | ||
}); | ||
}, | ||
{ | ||
onSuccess, | ||
onError, | ||
} | ||
); | ||
|
||
return ( | ||
<SimpleForm | ||
mutation={mutation} | ||
buttonText="Update" | ||
attributes={attributes} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
|
||
import BaseSSOForm from './BaseSSOForm'; | ||
import { Props } from './types'; | ||
|
||
export default function Okta(props: Props) { | ||
return <BaseSSOForm {...props} providerName="Okta" />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { Meta } from '@storybook/react'; | ||
|
||
import { NileProvider } from '../context'; | ||
|
||
import BaseSSOForm, { Okta } from '.'; | ||
|
||
const meta: Meta = { | ||
tags: ['autodocs'], | ||
component: BaseSSOForm, | ||
}; | ||
|
||
export default meta; | ||
|
||
export function BasicSSO() { | ||
return ( | ||
<NileProvider> | ||
<div style={{ maxWidth: '20rem', margin: '0 auto' }}> | ||
<BaseSSOForm | ||
providerName="placeholder" | ||
onSuccess={() => alert('success!')} | ||
/> | ||
</div> | ||
</NileProvider> | ||
); | ||
} | ||
export function OktaSSO() { | ||
return ( | ||
<NileProvider> | ||
<div style={{ maxWidth: '20rem', margin: '0 auto' }}> | ||
<Okta | ||
onSuccess={() => { | ||
alert('success!'); | ||
}} | ||
/> | ||
</div> | ||
</NileProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as Okta } from './Okta'; | ||
export { default } from './BaseSSOForm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { GetSSOProvider200Response } from '@theniledev/browser'; | ||
|
||
export type Props = { | ||
config?: GetSSOProvider200Response; | ||
onSuccess?: (data: unknown, variables: unknown) => void; | ||
onError?: (e: Error) => void; | ||
allowEdit?: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.