0

I am doing Google Oath2 Implementation. For a particular authorization_code, I was constantly getting invalid_grant. I checked the value and found that the query string value was encoded.

Here is an example:

const parser = require('url');
url ='http://example.com/test?param=4%2F12'
const q = parser.parse(url, true).query
console.log(q)

My output here is

{ param: '4/12' }

I want my output to be

{ param: '4%2F12' }

as the correct auth code is a string with value 4%2F12. How do I implement this?. There may be many manual ways to do this. Anything that needs a minimalistic code effort would be appreciated. Thanks in advance!

1
  • @LaodeMuhammadAlFatih Thanks for your help! I guess this should work Commented Jun 23, 2020 at 9:58

1 Answer 1

3

Simple. Just encode again the param using encodeURIComponent.

Example:

console.log(encodeURIComponent("4/12")) // Output: 4%2F12

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.