Home > Blockchain >  How can I get the correct format for the link?
How can I get the correct format for the link?

Time:09-30

It is necessary to convert this address to the correct format, since there is a space between the code id_token and openid accounts, which will not allow to follow the link correctly.

If I understand correctly the first thing I need to do is decode my url and then decrypt it?

https://api.mandarine.sai.com/authorize
    ?client_id=CLIENT_ID
    &response_type=code id_token
    &scope=openid accounts
    &redirect_uri=REDIRECT_URI
    &request=CONSENT_ID

But after I do this, I can't see the full address in the logs and I'm not sure if it's correct.

Here is my log:

[size=270 text=https://api.mandarine.sai.com/authorize?client_id=P1zLA3tA6nYG…]

And here is my code:

operator fun invoke(consentId: String): String {
        val url: String =  "$authorizeUrl?client_id=$clientId&response_type=code id_token&scope=openid accounts&redirect_uri=$redirect_uri&request=$consentId"
        val decodeUrl: String = URLDecoder.decode(url, "UTF-8")
        val encodeUrl: String = decodeUrl.encode().toString()
        return encodeUrl
    }

CodePudding user response:

I can use the replace function, but as for me, this is not quite an elegant solution:

val authorizeUrl: String = url.replace(" ", " ")

CodePudding user response:

You need to encode your url. In your code you are doing decoding and then encoding with extension function.

Encode URL:

operator fun invoke(consentId: String): String {
   val url: String =  "$authorizeUrl?client_id=$clientId&response_type=code id_token&scope=openid accounts&redirect_uri=$redirect_uri&request=$consentId"
   return URLEncoder.encode(url, "UTF-8");
}

Decode URL:

fun decodeLink(link : String) : String{
   try {
        return URLDecoder.decode(link,"UTF-8");
    }catch (Exception ignored){ }
    return link;
}
  • Related