Skip to content

Commit

Permalink
Merge branch 'master' into realtime-channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert authored Jan 11, 2025
2 parents 99d0785 + 056a80b commit c9ca945
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import io.ktor.client.call.body
import io.ktor.client.request.parameter
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.client.statement.request
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.CoroutineScope
Expand All @@ -52,8 +51,10 @@ import kotlinx.datetime.Clock
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonObjectBuilder
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.encodeToJsonElement
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.put
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -152,8 +153,9 @@ internal class AuthImpl(
val url = getOAuthUrl(provider, redirectTo, "user/identities/authorize", config)
val response = api.rawRequest(url) {
method = HttpMethod.Get
parameter("skip_http_redirect", true)
}
response.request.url.toString()
response.body<JsonObject>()["url"]?.jsonPrimitive?.contentOrNull ?: error("No URL found in response")
}
if(!automaticallyOpen) {
return fetchUrl(redirectUrl ?: "")
Expand Down
10 changes: 8 additions & 2 deletions Auth/src/commonTest/kotlin/AuthApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class AuthRequestTest {
val expectedRedirectUrl = "https://example.com"
val expectedScopes = listOf("scope1", "scope2")
val expectedUrlParams = mapOf("key" to "value")
val providerUrl = "https://example.com"
val client = createMockedSupabaseClient(configuration = configuration) {
val params = it.url.parameters
assertEquals(expectedRedirectUrl, params["redirect_to"])
Expand All @@ -330,14 +331,19 @@ class AuthRequestTest {
assertEquals(expectedScopes.joinToString(" "), params["scopes"])
assertEquals("value", params["key"])
respondJson(
sampleUserSession()
"""
{
"url": "$providerUrl"
}
""".trimIndent()
)
}
client.auth.linkIdentity(expectedProvider, redirectUrl = expectedRedirectUrl) {
val url = client.auth.linkIdentity(expectedProvider, redirectUrl = expectedRedirectUrl) {
scopes.addAll(expectedScopes)
queryParams.putAll(expectedUrlParams)
automaticallyOpenUrl = false
}
assertEquals(providerUrl, url)
}
}

Expand Down

0 comments on commit c9ca945

Please sign in to comment.