Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.http.HttpHeaders
- import org.springframework.http.MediaType
- import org.springframework.security.core.Authentication
- import org.springframework.security.web.server.authentication.logout.ServerLogoutHandler
- import org.springframework.stereotype.Component
- import org.springframework.web.reactive.function.BodyInserters
- import org.springframework.web.reactive.function.client.WebClient
- import org.springframework.web.server.ServerWebExchange
- import reactor.core.publisher.Mono
- @Component
- class CustomLogoutHandler : ServerLogoutHandler {
- override fun logout(exchange: ServerWebExchange?, authentication: Authentication?): Mono<Void> {
- val tokenToRemove = "TOKEN_TO_BE_REMOVED" // Replace with actual token
- val client = WebClient.create("https://oauth-provider.com/logout") // Replace with logout endpoint
- return client.post()
- .contentType(MediaType.APPLICATION_FORM_URLENCODED)
- .header(HttpHeaders.AUTHORIZATION, "Bearer $tokenToRemove")
- .exchangeToMono { response ->
- if (response.statusCode().is2xxSuccessful) {
- println("Successfully revoked token: $tokenToRemove")
- } else {
- println("Failed to revoke token: $tokenToRemove")
- }
- Mono.empty()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment