Skip to content

Commit

Permalink
WebFlux update logout url to port 3001
Browse files Browse the repository at this point in the history
  • Loading branch information
patkub committed Nov 6, 2024
1 parent 468af69 commit 26e9d9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mvc-login/src/main/java/org/example/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ private LogoutHandler logoutHandler() {
return (request, response, authentication) -> {
try {
String baseUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();
// The URL to log the user out of Auth0 and redirect them to the home page.
// URL will look like https://YOUR-DOMAIN/v2/logout?clientId=YOUR-CLIENT-ID&returnTo=http://localhost:3000
response.sendRedirect(issuer + "v2/logout?client_id=" + clientId + "&returnTo=" + baseUrl);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
8 changes: 4 additions & 4 deletions webflux-login/src/main/java/org/example/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
@EnableWebFluxSecurity
public class SecurityConfig {

@Value("${okta.oauth2.issuer}")
@Value("${spring.security.oauth2.client.provider.okta.issuer-uri}")
private String issuer;
@Value("${okta.oauth2.client-id}")
@Value("${spring.security.oauth2.client.registration.okta.client-id}")
private String clientId;

@Bean
Expand All @@ -45,10 +45,10 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
@Bean
public ServerLogoutSuccessHandler logoutSuccessHandler() {
// Change this as needed to URI where users should be redirected to after logout
String returnTo = "http://localhost:3000/";
String returnTo = "http://localhost:3001/";

// Build the URL to log the user out of Auth0 and redirect them to the home page.
// URL will look like https://YOUR-DOMAIN/v2/logout?clientId=YOUR-CLIENT-ID&returnTo=http://localhost:3000
// URL will look like https://YOUR-DOMAIN/v2/logout?clientId=YOUR-CLIENT-ID&returnTo=http://localhost:3001
String logoutUrl = UriComponentsBuilder
.fromHttpUrl(issuer + "v2/logout?client_id={clientId}&returnTo={returnTo}")
.encode()
Expand Down

0 comments on commit 26e9d9c

Please sign in to comment.