Skip to content

Commit d9e4184

Browse files
authored
Fix(google-jvm): Use dynamically found port for redirect URI (#165)
The redirect URI for Google authentication on JVM was previously hardcoded to use port 8080. This change updates the implementation to use the same dynamically discovered available port that the embedded Netty server listens on. This ensures the `redirect_uri` parameter in the authentication URL matches the actual callback server address, fixing authentication failures that would occur if port 8080 was already in use.
1 parent 6f22d60 commit d9e4184

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kmpauth-google/src/jvmMain/kotlin/com/mmk/kmpauth/google/GoogleAuthUiProviderImpl.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import java.nio.charset.StandardCharsets
2525
import java.security.SecureRandom
2626
import java.util.Base64
2727

28+
29+
private var foundAvailablePort: Int = 8080 //TODO temporary solution. Fix later in signin by passing redirect url
30+
2831
internal class GoogleAuthUiProviderImpl(private val credentials: GoogleAuthCredentials) :
2932
GoogleAuthUiProvider {
3033

@@ -38,7 +41,7 @@ internal class GoogleAuthUiProviderImpl(private val credentials: GoogleAuthCrede
3841
): GoogleUser? {
3942
val responseType = "id_token token"
4043
val scopeString = scopes.joinToString(" ")
41-
val redirectUri = "http://localhost:8080/callback"
44+
val redirectUri = "http://localhost:$foundAvailablePort/callback"
4245
val state: String
4346
var nonce: String?
4447
val googleAuthUrl = withContext(Dispatchers.IO) {
@@ -111,8 +114,8 @@ internal class GoogleAuthUiProviderImpl(private val credentials: GoogleAuthCrede
111114
}
112115
}
113116
""".trimIndent()
114-
115-
val server = embeddedServer(Netty, port = findAvailablePort()) {
117+
foundAvailablePort = findAvailablePort()
118+
val server = embeddedServer(Netty, port = foundAvailablePort) {
116119
routing {
117120
get(redirectUriPath) {
118121
call.respondHtml {

0 commit comments

Comments
 (0)