diff --git a/library/src/main/java/org/casdoor/Casdoor.kt b/library/src/main/java/org/casdoor/Casdoor.kt index d46f94a..905a8cf 100644 --- a/library/src/main/java/org/casdoor/Casdoor.kt +++ b/library/src/main/java/org/casdoor/Casdoor.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor import com.squareup.moshi.Moshi @@ -49,7 +50,7 @@ class Casdoor(private val config: CasdoorConfig) { */ fun getSignInUrl(scope: String? = null, state: String? = null): String { this.codeVerifier = Utils.generateCodeVerifier() - val url = "${config.endpoint}login/oauth/authorize" + val url = "${config.endpoint}/login/oauth/authorize" this.nonce = Utils.generateNonce() val query = CodeRequestQuery( config = config, @@ -81,7 +82,7 @@ class Casdoor(private val config: CasdoorConfig) { */ fun requestOauthAccessToken(code: String): AccessTokenResponse { - var httpUrl = "${config.endpoint}login/oauth/access_token".toHttpUrlOrNull() + var httpUrl = "${config.endpoint}/login/oauth/access_token".toHttpUrlOrNull() httpUrl ?: throw IllegalArgumentException("Invalid URL") httpUrl = AccessTokenRequest( code = code, @@ -110,7 +111,7 @@ class Casdoor(private val config: CasdoorConfig) { */ fun renewToken(refreshToken: String, scope: String? = null): AccessTokenResponse { - var httpUrl = "${config.endpoint}login/oauth/refresh_token".toHttpUrlOrNull() + var httpUrl = "${config.endpoint}/login/oauth/refresh_token".toHttpUrlOrNull() httpUrl ?: throw IllegalArgumentException("Invalid URL") httpUrl = RenewAccessTokenRequest( refreshToken = refreshToken, @@ -138,7 +139,7 @@ class Casdoor(private val config: CasdoorConfig) { * Logout. */ fun logout(idToken: String, state: String? = null): Boolean { - var httpUrl = "${config.endpoint}login/oauth/logout".toHttpUrlOrNull() + var httpUrl = "${config.endpoint}/login/oauth/logout".toHttpUrlOrNull() httpUrl ?: throw IllegalArgumentException("Invalid URL") httpUrl = httpUrl.newBuilder() .addQueryParameter("id_token_hint", idToken) diff --git a/library/src/main/java/org/casdoor/CasdoorConfig.kt b/library/src/main/java/org/casdoor/CasdoorConfig.kt index aac5dd9..688069f 100644 --- a/library/src/main/java/org/casdoor/CasdoorConfig.kt +++ b/library/src/main/java/org/casdoor/CasdoorConfig.kt @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor /** * * - * Casdoor Config Model + * Casdoor Config */ data class CasdoorConfig( val clientID: String, @@ -26,17 +27,4 @@ data class CasdoorConfig( val redirectUri: String, var endpoint: String, val appName: String, -) { - - - init { - endpoint = formatEndpoint(endpoint) - } - - private fun formatEndpoint(url: String): String { - val trimmedUrl = url.trim() - return if (trimmedUrl.endsWith("/")) trimmedUrl else "$trimmedUrl/" - } - - -} +) diff --git a/library/src/main/java/org/casdoor/Models.kt b/library/src/main/java/org/casdoor/Models.kt index 28217ef..aeefda5 100644 --- a/library/src/main/java/org/casdoor/Models.kt +++ b/library/src/main/java/org/casdoor/Models.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor import com.squareup.moshi.Json diff --git a/library/src/main/java/org/casdoor/Utils.kt b/library/src/main/java/org/casdoor/Utils.kt index 32388b4..a471fe4 100644 --- a/library/src/main/java/org/casdoor/Utils.kt +++ b/library/src/main/java/org/casdoor/Utils.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor import android.util.Base64 diff --git a/library/src/test/java/org/casdoor/CasdoorConfigTest.kt b/library/src/test/java/org/casdoor/CasdoorConfigTest.kt index 83f9635..4e32e2a 100644 --- a/library/src/test/java/org/casdoor/CasdoorConfigTest.kt +++ b/library/src/test/java/org/casdoor/CasdoorConfigTest.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor import org.junit.Assert.assertEquals diff --git a/library/src/test/java/org/casdoor/UtilsTest.kt b/library/src/test/java/org/casdoor/UtilsTest.kt index 7a9a119..2b77512 100644 --- a/library/src/test/java/org/casdoor/UtilsTest.kt +++ b/library/src/test/java/org/casdoor/UtilsTest.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.casdoor import org.junit.Assert.assertEquals