Skip to content

Commit

Permalink
Remove slash in endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Dec 22, 2023
1 parent 77d23a3 commit 9bbbcd0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
9 changes: 5 additions & 4 deletions library/src/main/java/org/casdoor/Casdoor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 3 additions & 15 deletions library/src/main/java/org/casdoor/CasdoorConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,18 @@
* 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,
val organizationName: String,
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/"
}


}
)
1 change: 1 addition & 0 deletions library/src/main/java/org/casdoor/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/src/main/java/org/casdoor/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/src/test/java/org/casdoor/CasdoorConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/src/test/java/org/casdoor/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9bbbcd0

Please sign in to comment.