Skip to content

Commit

Permalink
Add optional returnTo parameter to getLogoutUrl (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthadley authored Jan 15, 2025
1 parent cffbbd7 commit f4c389e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,13 @@ class UserManagementApi(private val workos: WorkOS) {
}

/** End a user's session. The user's browser should be redirected to this URL. */
fun getLogoutUrl(sessionId: String): String {
fun getLogoutUrl(sessionId: String, returnTo: String? = null): String {
return URIBuilder(workos.baseUrl)
.setPath("/user_management/sessions/logout")
.addParameter("session_id", sessionId)
.apply {
addParameter("session_id", sessionId)
returnTo?.let { addParameter("return_to", it) }
}
.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1622,4 +1622,14 @@ class UserManagementApiTest : TestBase() {
url
)
}

@Test
fun getLogoutUrlWithReturnToShouldReturnValidUrlResponse() {
val url = workos.userManagement.getLogoutUrl("session_123", returnTo = "https://your-app.com")

assertEquals(
"http://localhost:${getWireMockPort()}/user_management/sessions/logout?session_id=session_123&return_to=https%3A%2F%2Fyour-app.com",
url
)
}
}

0 comments on commit f4c389e

Please sign in to comment.