Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support direct_sign_in param for sign-in uri #235

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LogtoAuthSession(
loginHint = signInOptions.loginHint,
firstScreen = signInOptions.firstScreen,
identifiers = signInOptions.identifiers,
directSignIn = signInOptions.directSignIn,
extraParams = signInOptions.extraParams,
includeReservedScopes = logtoConfig.includeReservedScopes,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.logto.sdk.android.type

import io.logto.sdk.core.type.DirectSignInOptions

class SignInOptions(
val redirectUri: String,
val prompt: String? = null,
val firstScreen: String? = null,
val identifiers: List<String>? = null,
val directSignIn: DirectSignInOptions? = null,
val loginHint: String? = null,
val extraParams: Map<String, String>? = null,
)
4 changes: 4 additions & 0 deletions kotlin-sdk/kotlin/src/main/kotlin/io/logto/sdk/core/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ object Core {
addQueryParameter(QueryKey.FIRST_SCREEN, it)
}

options.directSignIn?.let {
addQueryParameter(QueryKey.DIRECT_SIGN_IN, "${it.method}:${it.target}")
}

options.identifiers?.let {
addQueryParameter(QueryKey.IDENTIFIER, it.joinToString(" "))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.logto.sdk.core.constant

object DirectSignInMethod {
const val SOCIAL = "social"
const val SSO = "sso"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.logto.sdk.core.type

class DirectSignInOptions(
val method: String,
val target: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GenerateSignInUriOptions(
val loginHint: String? = null,
val firstScreen: String? = null,
val identifiers: List<String>? = null,
val directSignIn: DirectSignInOptions? = null,
val extraParams: Map<String, String>? = null,
val includeReservedScopes: Boolean? = true,
)
24 changes: 24 additions & 0 deletions kotlin-sdk/kotlin/src/test/kotlin/io/logto/sdk/core/CoreTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.logto.sdk.core
import com.google.common.truth.Truth.assertThat
import io.logto.sdk.core.constant.*
import io.logto.sdk.core.exception.UriConstructionException
import io.logto.sdk.core.type.DirectSignInOptions
import io.logto.sdk.core.type.GenerateSignInUriOptions
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.junit.Assert
Expand Down Expand Up @@ -317,6 +318,29 @@ class CoreTest {
}
}

@Test
fun `generateSignInUri should contain direct_sign_in if provided`() {
val directSignIn = DirectSignInOptions(
method = DirectSignInMethod.SOCIAL,
target = "google"
)

val signInUri = Core.generateSignInUri(
GenerateSignInUriOptions(
authorizationEndpoint = testAuthorizationEndpoint,
clientId = testClientId,
redirectUri = testRedirectUri,
codeChallenge = testCodeChallenge,
state = testState,
directSignIn = directSignIn,
)
)

signInUri.toHttpUrl().apply {
assertThat(queryParameterValues(QueryKey.DIRECT_SIGN_IN)).contains("${directSignIn.method}:${directSignIn.target}")
}
}

@Test
fun `generateSignInUri should contain extra params if provided`() {
val extraParamKey = "tenant_id"
Expand Down
Loading