Skip to content

Commit 6502ec6

Browse files
authored
Allow configuring custom logout redirect for oidc (#9006)
Adds the option to configure a custom redirect uri after the logout. This was requested so that an OIDC provider logout can also be triggered. Note that this does not work for the “logout everywhere” feature. This is accepted for the moment, as this would be more complex (not sure how to tell the oidc provider to terminate all sessions). Note that this also does not yet implement the other direction (if a user logs out of another app with the same OIDC provider, wk sessions are not terminated). This would also be a lot more complex. ### Steps to test: - Adapt logout redirect address in application.conf (e.g. to https://example.org) - Log out in wk, should be redirected. - When navigating to wk again, should still be logged out. ### Issues: - fixes #9004 ------ - [x] Removed dev-only changes like prints and application.conf edits - [x] Considered [common edge cases](../blob/master/.github/common_edge_cases.md)
1 parent 59b5564 commit 6502ec6

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

app/controllers/AuthenticationController.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,16 @@ class AuthenticationController @Inject()(
537537
}
538538

539539
def logout: Action[AnyContent] = sil.UserAwareAction.async { implicit request =>
540+
val redirectUrlStr: String = conf.SingleSignOn.OpenIdConnect.logoutRedirectUrl.getOrElse("/")
541+
val rawResultWithRedirect = Ok(Json.toJson(redirectUrlStr))
540542
request.authenticator match {
541543
case Some(authenticator) =>
542544
for {
543-
authenticatorResult <- combinedAuthenticatorService.discard(authenticator, Ok)
545+
authenticatorResult <- combinedAuthenticatorService.discard(authenticator, rawResultWithRedirect)
544546
_ = logger.info(f"User ${request.identity.map(_._id).getOrElse("id unknown")} logged out.")
545547
} yield authenticatorResult
546-
case _ => Future.successful(Ok)
548+
case _ =>
549+
Future.successful(rawResultWithRedirect)
547550
}
548551
}
549552

app/utils/WkConf.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class WkConf @Inject()(configuration: Configuration, certificateValidationServic
128128
val clientSecret: String = get[String]("singleSignOn.openIdConnect.clientSecret")
129129
val scope: String = get[String]("singleSignOn.openIdConnect.scope")
130130
val verboseLoggingEnabled: Boolean = get[Boolean]("singleSignOn.openIdConnect.verboseLoggingEnabled")
131+
val logoutRedirectUrl = getOptional[String]("singleSignOn.openIdConnect.logoutRedirectUrl")
131132
}
132133
}
133134

conf/application.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ singleSignOn {
142142
clientId = "myclient"
143143
clientSecret = "myClientSecret"
144144
scope = "openid profile email"
145+
logoutRedirectUrl = null
145146
verboseLoggingEnabled = false # always set to false in production to avoid logging secrets
146147
}
147148
}

frontend/javascripts/admin/rest_api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export async function loginUser(formValues: {
154154
return [activeUser, organization];
155155
}
156156

157-
export async function logoutUser(): Promise<void> {
158-
await Request.receiveJSON("/api/auth/logout", { method: "POST" });
157+
export async function logoutUser(): Promise<string> {
158+
return await Request.receiveJSON("/api/auth/logout", { method: "POST" });
159159
}
160160

161161
export async function logoutUserEverywhere(): Promise<void> {

frontend/javascripts/navbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,10 @@ function Navbar({ isAuthenticated }: { isAuthenticated: boolean }) {
774774

775775
const handleLogout = async (event: React.SyntheticEvent) => {
776776
event.preventDefault();
777-
await logoutUser();
777+
const redirectUrl = await logoutUser();
778778
Store.dispatch(logoutUserAction());
779779
// Hard navigation
780-
location.href = "/";
780+
location.href = redirectUrl;
781781
};
782782

783783
const version = useFetch(getVersion, null, []);

0 commit comments

Comments
 (0)