-
Notifications
You must be signed in to change notification settings - Fork 294
feat: add Enterprise Connect support #1227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f32b733
feat: add useEnterpriseConnect hook for Enterprise Connect
gyaneshgouraw 355ba33
fix: move spa-js augment out of src/, fix telemetry shape
gyaneshgouraw dbe3758
feat: add Enterprise Connect examples and remove local type augment
gyaneshgouraw 96c7a74
feat: add support for enterpriseConnect flag in Auth0Provider and upd…
gyaneshgouraw 7bf7692
feat: update examples and documentation for Enterprise Connect integr…
gyaneshgouraw 6311722
feat: add useEnterpriseConnect link to README and update Callback fun…
gyaneshgouraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| import { renderHook, waitFor } from '@testing-library/react'; | ||
| import { | ||
| isFederatedDomain as spaIsFederatedDomain, | ||
| Auth0Client, | ||
| } from '@auth0/auth0-spa-js'; | ||
| import useEnterpriseConnect from '../src/use-enterprise-connect'; | ||
| import { createWrapper } from './helpers'; | ||
|
|
||
| jest.mock('@auth0/auth0-spa-js'); | ||
|
|
||
| const clientMock = jest.mocked(new Auth0Client({ clientId: '', domain: '' })); | ||
| const federatedMock = jest.mocked(spaIsFederatedDomain); | ||
|
|
||
| describe('useEnterpriseConnect', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| clientMock.getConfiguration.mockReturnValue({ | ||
| domain: '__test_domain__', | ||
| clientId: '__test_client_id__', | ||
| }); | ||
| }); | ||
|
|
||
| it('calls isFederatedDomain with the configured domain and email domain', async () => { | ||
| federatedMock.mockResolvedValueOnce(true); | ||
| const wrapper = createWrapper(); | ||
| const { result } = renderHook(() => useEnterpriseConnect(), { wrapper }); | ||
|
|
||
| const federated = await result.current.isFederatedDomain('acme.com'); | ||
|
|
||
| expect(federatedMock).toHaveBeenCalledWith( | ||
| '__test_domain__', | ||
| 'acme.com', | ||
| undefined | ||
| ); | ||
| expect(federated).toBe(true); | ||
| }); | ||
|
|
||
| it('forwards options to isFederatedDomain', async () => { | ||
| federatedMock.mockResolvedValueOnce(false); | ||
| const customFetch = jest.fn(); | ||
| const wrapper = createWrapper(); | ||
| const { result } = renderHook(() => useEnterpriseConnect(), { wrapper }); | ||
|
|
||
| await result.current.isFederatedDomain('acme.com', { customFetch }); | ||
|
|
||
| expect(federatedMock).toHaveBeenCalledWith('__test_domain__', 'acme.com', { | ||
| customFetch, | ||
| }); | ||
| }); | ||
|
|
||
| it('loginWithSSO calls loginWithRedirect with login_hint set from the email', async () => { | ||
| const wrapper = createWrapper(); | ||
| const { result } = renderHook(() => useEnterpriseConnect(), { wrapper }); | ||
| await waitFor(() => | ||
| expect(clientMock.loginWithRedirect).not.toBeNull() | ||
| ); | ||
|
|
||
| await result.current.loginWithSSO('jane@acme.com'); | ||
|
|
||
| expect(clientMock.loginWithRedirect).toHaveBeenCalledWith({ | ||
| authorizationParams: { login_hint: 'jane@acme.com' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('loginWithSSO preserves caller authorizationParams and other options', async () => { | ||
| const wrapper = createWrapper(); | ||
| const { result } = renderHook(() => useEnterpriseConnect(), { wrapper }); | ||
|
|
||
| await result.current.loginWithSSO('jane@acme.com', { | ||
| authorizationParams: { | ||
| connection: 'okta', | ||
| organization: 'org_123', | ||
| }, | ||
| appState: { returnTo: '/dashboard' }, | ||
| }); | ||
|
|
||
| expect(clientMock.loginWithRedirect).toHaveBeenCalledWith({ | ||
| appState: { returnTo: '/dashboard' }, | ||
| authorizationParams: { | ||
| connection: 'okta', | ||
| organization: 'org_123', | ||
| login_hint: 'jane@acme.com', | ||
| }, | ||
| }); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.