diff --git a/packages/core/src/SDKCore/SDKCore.ts b/packages/core/src/SDKCore/SDKCore.ts index 715ee9b..5a24b25 100644 --- a/packages/core/src/SDKCore/SDKCore.ts +++ b/packages/core/src/SDKCore/SDKCore.ts @@ -23,6 +23,7 @@ export class SDKCore { registerPath: config.registerPath, logoutPath: config.logoutPath, tokenRefreshPath: config.tokenRefreshPath, + postLogoutRedirectUri: config.postLogoutRedirectUri, }); this.scheduleTokenExpiration(); } diff --git a/packages/core/src/UrlHelper/UrlHelper.test.ts b/packages/core/src/UrlHelper/UrlHelper.test.ts index 2db59ae..8f18eb9 100644 --- a/packages/core/src/UrlHelper/UrlHelper.test.ts +++ b/packages/core/src/UrlHelper/UrlHelper.test.ts @@ -8,6 +8,7 @@ describe('UrlHelper', () => { clientId: 'abc123', redirectUri: 'http://my-client', scope: 'openid email profile offline_access', + postLogoutRedirectUri: 'http://example.com', }; const urlHelper = new UrlHelper(config); @@ -49,7 +50,29 @@ describe('UrlHelper', () => { expect(logoutUrl.pathname).toBe('/app/logout'); expect(logoutUrl.searchParams.get('client_id')).toBe(config.clientId); expect(logoutUrl.searchParams.get('post_logout_redirect_uri')).toBe( - config.redirectUri, + config.postLogoutRedirectUri, + ); + }); + + it('logout url - default post_logout_redirect_uri', () => { + const configWithoutPostLogoutRedirectUri: UrlHelperConfig = { + serverUrl: 'http://my-server', + clientId: 'abc123', + redirectUri: 'http://my-client', + scope: 'openid email profile offline_access', + }; + + const urlHelperWithoutPostLogoutRedirectUri = new UrlHelper( + configWithoutPostLogoutRedirectUri, + ); + const logoutUrl = urlHelperWithoutPostLogoutRedirectUri.getLogoutUrl(); + expect(logoutUrl.origin).toBe(configWithoutPostLogoutRedirectUri.serverUrl); + expect(logoutUrl.pathname).toBe('/app/logout'); + expect(logoutUrl.searchParams.get('client_id')).toBe( + configWithoutPostLogoutRedirectUri.clientId, + ); + expect(logoutUrl.searchParams.get('post_logout_redirect_uri')).toBe( + configWithoutPostLogoutRedirectUri.redirectUri, ); }); diff --git a/packages/core/src/UrlHelper/UrlHelper.ts b/packages/core/src/UrlHelper/UrlHelper.ts index 288c65c..3864b4d 100644 --- a/packages/core/src/UrlHelper/UrlHelper.ts +++ b/packages/core/src/UrlHelper/UrlHelper.ts @@ -12,12 +12,14 @@ export class UrlHelper { registerPath: string; logoutPath: string; tokenRefreshPath: string; + postLogoutRedirectUri?: string; constructor(config: UrlHelperConfig) { this.serverUrl = config.serverUrl; this.clientId = config.clientId; this.redirectUri = config.redirectUri; this.scope = config.scope; + this.postLogoutRedirectUri = config.postLogoutRedirectUri; this.mePath = config.mePath ?? '/app/me'; this.loginPath = config.loginPath ?? '/app/login'; @@ -51,7 +53,7 @@ export class UrlHelper { getLogoutUrl(): URL { return this.generateUrl(this.logoutPath, { client_id: this.clientId, - post_logout_redirect_uri: this.redirectUri, + post_logout_redirect_uri: this.postLogoutRedirectUri || this.redirectUri, }); } diff --git a/packages/core/src/UrlHelper/UrlHelperTypes.ts b/packages/core/src/UrlHelper/UrlHelperTypes.ts index 6737657..c3c54b3 100644 --- a/packages/core/src/UrlHelper/UrlHelperTypes.ts +++ b/packages/core/src/UrlHelper/UrlHelperTypes.ts @@ -12,6 +12,7 @@ export type UrlHelperConfig = Pick< | 'logoutPath' | 'tokenRefreshPath' | 'scope' + | 'postLogoutRedirectUri' >; /** The query params associated with URLs generated by the UrlHelper class. */ diff --git a/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/core.ts b/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/core.ts index 7d72e5d..fbb78a4 100644 --- a/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/core.ts +++ b/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/core.ts @@ -48,7 +48,7 @@ class g { getLogoutUrl() { return this.generateUrl(this.logoutPath, { client_id: this.clientId, - post_logout_redirect_uri: this.redirectUri, + post_logout_redirect_uri: this.postLogoutRedirectUri || this.redirectUri, }); } getTokenRefreshUrl() { @@ -122,6 +122,7 @@ class U { serverUrl: e.serverUrl, clientId: e.clientId, redirectUri: e.redirectUri, + postLogoutRedirectUri: e.postLogoutRedirectUri, scope: e.scope, mePath: e.mePath, loginPath: e.loginPath, diff --git a/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/types.ts b/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/types.ts index 96355b9..8dffbb4 100644 --- a/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/types.ts +++ b/packages/sdk-angular/projects/fusionauth-angular-sdk/src/lib/types.ts @@ -17,6 +17,11 @@ export interface FusionAuthConfig { */ redirectUri: string; + /** + * The redirect URI for post-logout. Defaults the provided `redirectUri`. + */ + postLogoutRedirectUri?: string; + /** * The OAuth2 scope parameter passed to the `/oauth2/authorize` endpoint. If not specified fusionauth will default this to `openid offline_access`. */ diff --git a/packages/sdk-react/src/components/providers/FusionAuthProviderConfig.ts b/packages/sdk-react/src/components/providers/FusionAuthProviderConfig.ts index 7544408..114c240 100644 --- a/packages/sdk-react/src/components/providers/FusionAuthProviderConfig.ts +++ b/packages/sdk-react/src/components/providers/FusionAuthProviderConfig.ts @@ -22,6 +22,11 @@ export interface FusionAuthProviderConfig { */ scope?: string; + /** + * The redirect URI for post-logout. Defaults the provided `redirectUri`. + */ + postLogoutRedirectUri?: string; + /** * Enables automatic token refreshing. Defaults to false. */ diff --git a/packages/sdk-react/src/testing-tools/mocks/testConfig.ts b/packages/sdk-react/src/testing-tools/mocks/testConfig.ts index cdef8c7..733607e 100644 --- a/packages/sdk-react/src/testing-tools/mocks/testConfig.ts +++ b/packages/sdk-react/src/testing-tools/mocks/testConfig.ts @@ -5,4 +5,5 @@ export const TEST_CONFIG: FusionAuthProviderConfig = { serverUrl: 'http://localhost:9000', redirectUri: 'http://localhost', scope: 'openid email profile offline_access', + postLogoutRedirectUri: 'http://localhost', }; diff --git a/packages/sdk-vue/src/types.ts b/packages/sdk-vue/src/types.ts index 947d04c..bde81e4 100644 --- a/packages/sdk-vue/src/types.ts +++ b/packages/sdk-vue/src/types.ts @@ -18,6 +18,11 @@ export interface FusionAuthConfig { */ redirectUri: string; + /** + * The redirect URI for post-logout. Defaults the provided `redirectUri`. + */ + postLogoutRedirectUri?: string; + /** * The OAuth2 scope parameter passed to the `/oauth2/authorize` endpoint. If not specified fusionauth will default this to `openid offline_access`. */