Skip to content

Commit

Permalink
fix(security): base URL of oauth2 URI was hardcoded as localhost, thu…
Browse files Browse the repository at this point in the history
…s it was not possible to use proxy/custom domain. Switched to using redirect URI templating fixing the problem.
  • Loading branch information
filipowm committed Mar 5, 2022
1 parent 5d41393 commit 490da0c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ internal class ClientRegistrationRegistrar(private val projectSourcesProperties:
if (clientRegistrations.isEmpty()) {
throw IllegalStateException("No valid client registration")
}
log.info("Registered OAuth2 clients: {}", clientRegistrations.joinToString { it.clientName })
log.info("Registered OAuth2 clients: {}", clientRegistrations.joinToString { it.asHumanReadable() })
return InMemoryReactiveClientRegistrationRepository(clientRegistrations)
}

private fun ClientRegistration.asHumanReadable(): String {
return "$clientName (redirect-uri=${redirectUri},scopes=(${scopes.joinToString(", ")}))"
}

private fun completeRegistration(partialRegistration: ClientRegistration): ClientRegistration {
return ClientRegistration.withClientRegistration(partialRegistration)
.clientSecret(projectSourcesProperties.clientSecret)
.clientId(projectSourcesProperties.clientId)
.redirectUri("http://localhost:8080/login/oauth2/code/gitlab")
.redirectUri("{baseUrl}/login/oauth2/code/${partialRegistration.registrationId}")
.authorizationGrantType(partialRegistration.authorizationGrantType ?: DEFAULT_AUTHORIZATION_GRANT_TYPE)
.build()
}
Expand Down

0 comments on commit 490da0c

Please sign in to comment.