Welcome Guest, Not a member yet? Register   Sign In
Base64 encoding
#1

(This post was last modified: 09-18-2021, 10:31 AM by richb201.)

I am using the fusionAuth server and trying to send the server an address to send my user to once they are authenticated. I am setting the field like this:
$request["state"]["redirect_uri"] =urlEncode( "https://researchstudyonline.com:81/index.php/Configure/report_generator_amazing");
But I am getting an error from the server saying that there is "something wrong" with my url. This is the exact text: 
We're sorry, your request was malformed or was unable to be completed for some reason. Try hitting the back button and restarting the process to see if it fixes the problem.
"error_description" : "Invalid redirect uri https%3A%2F%2Fresearchstudyonline.com%3A81%2Findex.php%2FConfigure%2Freport_generator_amazing",

I noticed in some example the author created a function called base64URLEncode which seems to replace "_" and "-" and "". Underscores are clearly in my URL. Is there some built in function in CI3 for doing this type of encoding? Here is the function:
Code:
function base64URLEncode(str) {
  return str.toString('base64')
    .replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=/g, '');
}

Is there any other type of encoding that you could recommend trying? I also tried 
$r$request["state"]["redirect_uri"] =base64_encode( "https://researchstudyonline.com:81/index.php/Configure/report_generator_amazing");

but that didn't work either.
proof that an old dog can learn new tricks
Reply
#2

You do not want to use base64_encode.

php.net - urlencode

Try reading that.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-19-2021, 12:45 AM)InsiteFX Wrote: You do not want to use base64_encode.

php.net - urlencode

Try reading that.

Thanks, I already tried that but it is not working. Must be something else. 
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 09-20-2021, 04:27 PM by richb201.)

urlencode actually seems different.
"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs."

I read this as urlencode is ignoring - and _. I need to modify these as per the code above.

The base64URLEncode function above replaces both of these. What to do?

I'd like to simulate this function in php. How?


  return str.toString('base64')
    .replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=/g, '');
}
proof that an old dog can learn new tricks
Reply
#5

Pure PHP
PHP Code:
return str_replace(
    [
'+''/''='],
    [
'-''_'''],
    
base64_encode($yourString)
); 
Reply
#6

Thanks. I am having a small problem with my server setup. I'll try it out as soon as I can!
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB