From 1e7c27ec5cb5f23eea4c718ffb9f594400a9fc2d Mon Sep 17 00:00:00 2001 From: Besmir Beqiri Date: Tue, 14 May 2024 14:55:19 +0200 Subject: [PATCH] Fix the server url when `useLoopbackIpAddress` OAuth2 option is used --- CHANGELOG.md | 2 ++ .../auth/core/oauth2/OAuth2AuthenticationProvider.java | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 909046f6..fc90854d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ### 0.3.2-SNAPSHOT (TBD) +#### Bugfixes +Fix the server url when `useLoopbackIpAddress` OAuth2 option is used. ---------------------- diff --git a/jpro-auth/core/src/main/java/one/jpro/platform/auth/core/oauth2/OAuth2AuthenticationProvider.java b/jpro-auth/core/src/main/java/one/jpro/platform/auth/core/oauth2/OAuth2AuthenticationProvider.java index b5630352..33da7e36 100755 --- a/jpro-auth/core/src/main/java/one/jpro/platform/auth/core/oauth2/OAuth2AuthenticationProvider.java +++ b/jpro-auth/core/src/main/java/one/jpro/platform/auth/core/oauth2/OAuth2AuthenticationProvider.java @@ -669,15 +669,16 @@ private String normalizeUri(String uri) { if (httpServer != null && redirectUri != null && redirectUri.charAt(0) == '/') { final int port = httpServer.getServerPort(); String server = httpServer.getServerHost(); + boolean isLocalAddress = false; final String loopbackAddress = InetAddress.getLoopbackAddress().getHostAddress(); - if (options.isUseLoopbackIpAddress()) { + if (options.isUseLoopbackIpAddress() && server.equals("localhost")) { server = loopbackAddress; + isLocalAddress = true; } - final boolean localAddress = server.equals("localhost") || server.equals(loopbackAddress); if (port > 0) { server += ":" + port; } - final String serverUrl = localAddress ? "http://" + server : "https://" + server; + final String serverUrl = isLocalAddress ? "http://" + server : "https://" + server; redirectUri = serverUrl + redirectUri; } return redirectUri;