Only use the base URL during onboarding if the URL is Nabu Casa (#3322)

* Only use the base URL during onboarding

* Use HttpUrl Builder to construct proper URL

* Move variable to try/catch block

* Only apply logic to NC URLs as those do not have custom path

* Only parse the end of the URL

* Deduplicate code per review
This commit is contained in:
Daniel Shokouhi 2023-09-17 13:55:38 -07:00 committed by GitHub
parent 50a8b9eee2
commit 9ece6c7c28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,6 +33,7 @@ import io.homeassistant.companion.android.onboarding.integration.MobileAppIntegr
import io.homeassistant.companion.android.themes.ThemesManager
import io.homeassistant.companion.android.util.TLSWebViewClient
import io.homeassistant.companion.android.util.isStarted
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import javax.inject.Inject
import io.homeassistant.companion.android.common.R as commonR
@ -166,8 +167,16 @@ class AuthenticationFragment : Fragment() {
private fun buildAuthUrl(base: String): String {
return try {
base.toHttpUrl()
.newBuilder()
val url = base.toHttpUrl()
val builder = if (url.host.endsWith("ui.nabu.casa", true)) {
HttpUrl.Builder()
.scheme(url.scheme)
.host(url.host)
.port(url.port)
} else {
url.newBuilder()
}
builder
.addPathSegments("auth/authorize")
.addEncodedQueryParameter("response_type", "code")
.addEncodedQueryParameter("client_id", AuthenticationService.CLIENT_ID)