oAuth 2 separate scopes with %20

Hello,

I’m working with SalesForce oAuth integration and I need to separate the scopes with a url encoded %20. If I put a space in the scope separator in Wappler, the scopes are sent in a url paramenter separated with a + sign. I’ve tried putting %20, + and %2B as scope separators without success.

Any suggestions?

Would the above be possible with the recently added ability to write our own modules, ie taking the current OAuth module and hardcoding the %20 instead of + for URL encoded spaces, @Teodor, @George ?

I still haven’t found a solution to this day.

Thanks for your insights.

Maybe @patrick should check out the right way to use multiple scopes so it works always

Are you using PHP, ASP or NodeJS?

The plus sign is btw the correct encoding according to the http specs. Strange that SalesForce does not support that. Seeing also other users having problem with it.

https://developer.salesforce.com/forums/?id=906F0000000kEnYIAU

I’m using PHP.



From: noreply@community.wappler.io
Sent: 28 October 2020 18:13
To: nathaniel.bujalance@gmail.com
Reply to: replies+880f838234533b1fbf78390ee121d9a5@wappler.io
Subject: [Wappler Community] [Wappler General/How To] oAuth 2 separate scopes with %20

patrick Team
October 28

Are you using PHP, ASP or NodeJS?

SalesForce seems not to adhere to standardize OAuth in many aspects, until a few months back you could use only one scope, but recently and without warning they have enforced two scope in order to get a refresh token.
In my case this is a big deal and my only way out is to write full custom code, but if there is a way of using Wappler to meet these requirements, it would really go a long way. I don’t know how many other users in this community may be benefit from this though, if it were to come from a feature within wappler, but if there is a way to hack or modify the current behavior, I’m more than willing to take it and write a tutorial on the subsequent implementation, my next few weeks are going to be fully oriented with working on several instances of SFDC.

The url for OAuth is build in dmxConnectLib/lib/oauth/Oauth2.php line 153.

$uri .= http_build_query($params);

change it to:

$uri .= http_build_query($params, null, '&', PHP_QUERY_RFC3986);

https://www.php.net/manual/en/function.http-build-query.php

Thanks very much @patrick, I’ll be testing this in the next week. The support you all provide is invaluable.

Hi @patrick,
I just started working on this, on my copy of dmxConnectLib/lib/oauth/Oauth2.php, the above was found in line 170, and when running the action, I get an error 500. On checking it a little closer, I get this error returned:
Fatal error: Cannot redeclare lib\oauth\Oauth2::get() in /volume1/web/instance_1/dmxConnectLib/lib/oauth/Oauth2.php on line 189

I get the same error when reverting to the original page/code, I wonder if something has been introduced since we last exchanged (I’m using wappler 3.5.1) that affects everyone, since there is an obvious delta with the line numbers.

With the 2 last Wappler updates a lot changed, OAuth2 can be used globally and the code for it was updated.

Here the latest version:

Oauth2.zip (3.0 KB)

The http_build_query function is now located at line 295.

Thanks @Patrick. How do these updates work with existing websites? I’m assuming that when creating an action/step, the latest version is applied, but how are existing websites /apps affected when one updates wappler and there is a pre-existing version of a step that has been updated in between wappler upgrades?

Previous actions should still work, no update needed for them, if there are any issues then please post the issue and we will fix it. It should be backwards compatible.

Thanks Patrick, from a preliminary test, it now works and sends the scopes with a %20. I’ll continue working on this. :+1:

Hi @patrick,

I just upgraded to 3.5.2 and on my development environment, I know have this error in all pages:
{"code":0,"file":"\/volume1\/web\/instance_1\/dmxConnectLib\/modules\/auth.php","line":72,"message":"Call to undefined method lib\\auth\\Provider::get()","trace":"#0 \/volume1\/web\/instance_1\/dmxConnectLib\/lib\/App.php(193): modules\\auth->restrict(Object(stdClass), NULL)\n#1 \/volume1\/web\/instance_1\/dmxConnectLib\/lib\/App.php(157): lib\\App->execSteps(Object(stdClass))\n#2 \/volume1\/web\/instance_1\/dmxConnectLib\/lib\/App.php(127): lib\\App->execSteps(Array)\n#3 \/volume1\/web\/instance_1\/index.php(19): lib\\App->exec(Object(stdClass), true)\n#4 {main}"}
I did apply the last file you provided, but it hasn’t fixed it and I wonder if App.php needs also an upgrade? Oddly enough, my production environment didn’t break (thankfully enough).

I was editing my oauth server action and adding a get parameter, I see a reference there, it may come from there and the back compatibility of the global actions?

Updated the new file for you.

Oauth2.zip (3.0 KB)

Thanks @patrick. Am I doing something wrong or is there a glitch with the updates with existing sites?

The file was updated for the new globals and you probably replaced it with a older version that was not compatible with the update

I’m editing an existing app/site, I wonder where I am overwriting new files.
The new file didn’t fix the issue, I get the same error. I think it may come from the new input variables, I added a get parameter to my server action and that’s when I first noticed it didn’t work, and would explain why my prod is still working, since I didn’t upload the get parameter action there.