From d0f92efee3309ea9bd468162bb942b5cdc387de7 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Wed, 29 Nov 2023 16:53:40 +0800 Subject: [PATCH] fix(core): should add organization resource in generateSignInUri method --- .../src/main/kotlin/io/logto/sdk/core/Core.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kotlin-sdk/kotlin/src/main/kotlin/io/logto/sdk/core/Core.kt b/kotlin-sdk/kotlin/src/main/kotlin/io/logto/sdk/core/Core.kt index b9d2ab7c..3152ef3c 100644 --- a/kotlin-sdk/kotlin/src/main/kotlin/io/logto/sdk/core/Core.kt +++ b/kotlin-sdk/kotlin/src/main/kotlin/io/logto/sdk/core/Core.kt @@ -4,7 +4,9 @@ import io.logto.sdk.core.constant.CodeChallengeMethod import io.logto.sdk.core.constant.GrantType import io.logto.sdk.core.constant.PromptValue import io.logto.sdk.core.constant.QueryKey +import io.logto.sdk.core.constant.ReservedResource import io.logto.sdk.core.constant.ResponseType +import io.logto.sdk.core.constant.UserScope import io.logto.sdk.core.exception.UriConstructionException import io.logto.sdk.core.http.HttpCompletion import io.logto.sdk.core.http.HttpEmptyCompletion @@ -39,8 +41,19 @@ object Core { addQueryParameter(QueryKey.STATE, state) addQueryParameter(QueryKey.REDIRECT_URI, redirectUri) addQueryParameter(QueryKey.RESPONSE_TYPE, ResponseType.CODE) - addQueryParameter(QueryKey.SCOPE, ScopeUtils.withDefaultScopes(scopes).joinToString(" ")) - resources?.let { for (value in it) { addQueryParameter(QueryKey.RESOURCE, value) } } + + val usedScopes = ScopeUtils.withDefaultScopes(scopes) + addQueryParameter(QueryKey.SCOPE, usedScopes.joinToString(" ")) + + val usedResources = resources.orEmpty() + for (value in usedResources) { addQueryParameter(QueryKey.RESOURCE, value) } + if ( + usedScopes.contains(UserScope.ORGANIZATIONS) && + !usedResources.contains(ReservedResource.ORGANIZATION) + ) { + addQueryParameter(QueryKey.RESOURCE, ReservedResource.ORGANIZATION) + } + addQueryParameter(QueryKey.PROMPT, prompt ?: PromptValue.CONSENT) }.build().toString() }