Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encodeURIComponent not working as expected for verification service on node server #16

Closed
r-vianna opened this issue Apr 15, 2017 · 3 comments
Assignees

Comments

@r-vianna
Copy link

Hello,

I am currently running a node/express server to do license verification for my application. I am having issues I was able to work around but it does not follow the guidelines provided so I wanted to check if I am missing something.

Currently I am getting the et parameter and base64 decoding it

var token = new Buffer(req.query.et, 'base64').toString('ascii');

Then according to the guidelines I need to url encode this to send it to the verification service. If I use encodeURIComponent as suggested, I get the following url (this is based off of the sample token provided in the docs).

token = encodeURIComponent(token);

https://verificationservice.officeapps.live.com/ova/verificationagent.svc/rest/verify?token=%3C%00r%00%3E%00%0D%00%0A%00%20%00%20%00%3C%00t%00%20%00%0D%00%0A%00%20%00%20%00%20%00%20%00a%00i%00d%00%3D%00%22%00W%00A%009%000%000%000%000%006%000%005%006%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00p%00i%00d%00%3D%00%22%00%7B%004%00F%00B%006%000%001%00F%002%00-%005%004%006%009%00-%004%005%004%002%00-%00B%009%00F%00C%00-%00B%009%006%003%004%005%00D%00C%008%00B%003%009%00%7D%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00c%00i%00d%00%3D%00%22%003%002%00F%003%00E%007%00F%00C%005%005%009%00F%004%00F%004%009%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00e%00t%00%3D%00%22%00T%00r%00i%00a%00l%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00a%00d%00%3D%00%22%002%000%001%002%00-%000%001%00-%001%002%00T%002%001%00%3A%005%008%00%3A%001%003%00Z%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00e%00d%00%3D%00%22%002%000%001%002%00-%000%006%00-%003%000%00T%002%001%00%3A%005%008%00%3A%001%003%00Z%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00s%00d%00%3D%00%22%002%000%001%002%00-%000%001%00-%001%002%00T%000%000%00%3A%000%000%00%3A%000%000%00Z%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00t%00e%00%3D%00%22%002%000%001%002%00-%000%006%00-%003%000%00T%000%002%00%3A%004%009%00%3A%003%004%00Z%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00t%00s%00%3D%00%22%000%00%22%00%0D%00%0A%00%20%00%20%00%20%00%20%00t%00e%00s%00t%00%3D%00%22%00t%00r%00u%00e%00%22%00%2F%00%3E%00%0D%00%0A%00%20%00%20%00%3C%00d%00%3E%00V%00N%00N%00A%00n%00f%003%006%00I%00r%00k%00y%00U%00V%00Z%00l%00i%00h%00Q%00J%00N%00d%00U%00U%00Z%00l%00%2F%00Y%00F%00E%00f%00J%00O%00e%00l%00d%00W%00B%00t%00d%003%00I%00M%00%3D%00%3C%00%2F%00d%00%3E%00%0D%00%0A%00%3C%00%2F%00r%00%3E%00

This does not work (IsTest is false). However if I use some regex magic I do get a working response.

token = encodeURIComponent(token).replace(/%00|%0D/g, '').replace(/%20/g,'+');

https://verificationservice.officeapps.live.com/ova/verificationagent.svc/rest/verify?token=%3Cr%3E%0A++%3Ct+%0A++++aid%3D%22WA900006056%22%0A++++pid%3D%22%7B4FB601F2-5469-4542-B9FC-B96345DC8B39%7D%22%0A++++cid%3D%2232F3E7FC559F4F49%22%0A++++et%3D%22Trial%22%0A++++ad%3D%222012-01-12T21%3A58%3A13Z%22%0A++++ed%3D%222012-06-30T21%3A58%3A13Z%22%0A++++sd%3D%222012-01-12T00%3A00%3A00Z%22%0A++++te%3D%222012-06-30T02%3A49%3A34Z%22%0A++++ts%3D%220%22%0A++++test%3D%22true%22%2F%3E%0A++%3Cd%3EVNNAnf36IrkyUVZlihQJNdUUZl%2FYFEfJOeldWBtd3IM%3D%3C%2Fd%3E%0A%3C%2Fr%3E

Just wanted to clarify if I am doing something wrong or the documentation is out of date.

@PhilSmail
Copy link
Collaborator

encodeURIComponent does work but you do need to format it correctly

If you do a search for URLencoder on bing the code behind that does the following, which works:
encodeURIComponent(n).replace(/%20/g, "+")

@r-vianna
Copy link
Author

Thanks, I think it may be worth considering updating the docs to reflect the formatting aspect. From the following section:

The Office Store license verification web service also supports verifying add-in license tokens by using REST calls. To validate an add-in license by using REST, use the following syntax, where {token} is the add-in license token, encoded by a method that complies with RFC 2396. For example, the encodeURIComponent() function in JavaScript, or the Uri.EscapeDataString method in the .NET Framework:

It is not obvious (to me anyway) that extra steps are needed beyond using encodeURIComponent.
If you want I would be happy to write you a JavaScript example to use in the docs.

@draisy
Copy link

draisy commented May 26, 2017

Hi @PhilSmail,

I ran into the same issue as @r-vianna above and was not able to resolve it with your suggestion of

encodeURIComponent(n).replace(/%20/g, "+"),

but if I do it this way

encodeURIComponent(token).replace(/%00|%0D/g, '').replace(/%20/g,'+'),

then it works successfully. Could the docs be updated to reflect this to save others from this same issue?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants