Skip to content

Commit

Permalink
feat: Add silentRedirectUri option. (#528)
Browse files Browse the repository at this point in the history
Co-authored-by: Doug Swain <doug.swain@honeywell.com>
  • Loading branch information
pseudoramble and Doug Swain committed Mar 15, 2021
1 parent 3f61d6f commit a349d4d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const initUserManager = (props: AuthProviderProps): UserManager => {
clientId,
clientSecret,
redirectUri,
silentRedirectUri,
postLogoutRedirectUri,
responseType,
scope,
Expand All @@ -53,7 +54,7 @@ export const initUserManager = (props: AuthProviderProps): UserManager => {
client_id: clientId,
client_secret: clientSecret,
redirect_uri: redirectUri,
silent_redirect_uri: redirectUri,
silent_redirect_uri: silentRedirectUri || redirectUri,
post_logout_redirect_uri: postLogoutRedirectUri || redirectUri,
response_type: responseType || 'code',
scope: scope || 'openid',
Expand Down
4 changes: 4 additions & 0 deletions src/AuthContextInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export interface AuthProviderProps {
* The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider.
*/
redirectUri?: string;
/**
* The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider when completing a background sign-in refresh.
*/
silentRedirectUri?: string;
/**
* The post-logout redirect URI of your client application which your OIDC/OAuth2 provider can redirect to after completing logout.
*/
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/AuthContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ describe('AuthContext', () => {
expect.objectContaining({ post_logout_redirect_uri: 'http://127.0.0.1'})
));
});
it('should use silent redirect URI when given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
silentRedirectUri="https://localhost"
/>,
);
await waitFor(() => expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({ silent_redirect_uri: 'https://localhost'})
));
});
it('should fall back to redirectUri when silent redirect URI is not given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
await waitFor(() => expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({ silent_redirect_uri: 'http://127.0.0.1'})
));
});

it('should get userData', async () => {
await act(async () => {
Expand Down

0 comments on commit a349d4d

Please sign in to comment.