Skip to content

Commit

Permalink
46 Add postLogoutRedirectUri Param Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BriDavidson committed May 17, 2024
1 parent 6e32ba3 commit cd380c5
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/core/src/SDKCore/SDKCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class SDKCore {
registerPath: config.registerPath,
logoutPath: config.logoutPath,
tokenRefreshPath: config.tokenRefreshPath,
postLogoutRedirectUri: config.postLogoutRedirectUri,
});
this.scheduleTokenExpiration();
}
Expand Down
25 changes: 24 additions & 1 deletion packages/core/src/UrlHelper/UrlHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
});

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/UrlHelper/UrlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/UrlHelper/UrlHelperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type UrlHelperConfig = Pick<
| 'logoutPath'
| 'tokenRefreshPath'
| 'scope'
| 'postLogoutRedirectUri'
>;

/** The query params associated with URLs generated by the UrlHelper class. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-react/src/testing-tools/mocks/testConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
5 changes: 5 additions & 0 deletions packages/sdk-vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand Down

0 comments on commit cd380c5

Please sign in to comment.