Hi,
To have better user experience and new features in the abrp plugin, I need to implement oauth. I am at the last step, where I try to catch the answer of a request, which is a JSON containing the "access_token".
- to launch the abrp authentication page, with the oauth api, I used a webplugin, and it works well it the ovms box is connected to a wifi with internet.
- but I found no way, except facing CORS errors (cross domain origin) to catch the last answer, which is displayed.
If I launch the last call in a new web page, I have the result (see screen copy of firefox result).
https://pasteboard.co/J7HOhMq.tiff
So I tried to launch this url with the HTTP.request call in the plugin script, but I have an error, I am not sure about the meaning:
https://pasteboard.co/J7HNEs5.tiff
Could you help me to understand what is this error, please ?
kindly regards
David
Your screenshots are broken…
OK, I added links in the description :-)
The url I launch in firefox by hand : https://web.abetterrouteplanner.com/oauth/token?client_id=49&client_secret=32b2162f-9599-4647-8139-66e9f9528370&code=5972e204-3495-496d-9565-dc9ed5b0f7f0&redirect_uri=https://inexpensive-caterwauling-myrtle.glitch.me
The error I have when I try it with HTTP.request:
mongoose: mg_ssl_if_mbed_err 0x3f84e8a4 SSL error: -9984
Both links lead to "Image not found".
I assume you missed adding the CA PEM file to your trusted CA list as documented: https://docs.openvehicles.com/en/latest/userguide/ssltls.html
web.abetterrouteplanner.com currently uses a certificate by Cloudflare, so you need to add the Cloudflare CA, which is currently:
After adding this, your request succeeds on my module.
Regards,
Michael
I will try that, thanks a lot, Michael !
Michael,
Following your advice, I have done this:
So the error is not the same anymore, it definilty help to add the crt file, as I no longer have mongoose error, but as you said you got an answer trying it on your module, I was wondering what mistake I made...
kindly regards
David
David,
I assumed you don't want to use the oauth redirection in a HTTP.Request, as it doesn't seem to make sense to redirect a script to a user site.
So I did the request without the redirect parameter:
HTTP.Request({
url: "https://web.abetterrouteplanner.com/oauth/token?client_id=49&client_secret=32b2162f-9599-4647-8139-66e9f9528370&code=5972e204-3495-496d-9565-dc9ed5b0f7f0",
always: function() { JSON.print(this, false); }
});
Doing this creates this response:
I (143694) script: [eval:3:] {"url":"https://web.abetterrouteplanner.com/oauth/token?client_id=49&client_secret=32b2162f-9599-4647-8139-66e9f9528370&code=5972e204-3495-496d-9565-dc9ed5b0f7f0","always":function () { [ecmascript code] },"redirectCount":0,"error":"","response":{"statusCode":200,"statusText":"OK","body":"{\"access_token\": \"9c714107-56aa-4e4d-a318-80c3bf967e35\", \"token_type\": \"bearer\", \"state\": \"darkianiro63.local\"}","headers":[{"Date":"Wed, 13 May 2020 16:11:45 GMT"},{"Content-Type":"application/json"},{"Transfer-Encoding":"chunked"},{"Connection":"keep-alive"},{"Set-Cookie":"__cfduid=d23c2e76010a17a55f4101b64469a5cd31589386304; expires=Fri, 12-Jun-20 16:11:44 GMT; path=/; domain=.abetterrouteplanner.com; HttpOnly; SameSite=Lax"},{"Vary":"Accept-Encoding"},{"CF-Cache-Status":"DYNAMIC"},{"Expect-CT":"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""},{"Server":"cloudflare"},{"CF-RAY":"592da835d9d19bf7-AMS"},{"cf-request-id":"02b06775ab00009bf7d491c200000001"}]}}
That's a status 200 and has an access_token in the body, so seems to be a valid response.
If you actually want to let the script follow the redirect, you will need to add the CA for the redirect destination (inexpensive-caterwauling-myrtle.glitch.me) as well.
Regards,
Michael
Hi Michael !
This time, I feel really stupid. Of course you're right regarding the redirect.
So I upgraded my OVMS device to the latest version I found (3.2.012-225-g64499067), reboot. Then I've written exactly the same code as you, made a script reload and I still have this:
David,
if you take a closer look, your "cloudflare.crt" has changed in your last post.
It seems you meanwhile have exchanged the CA certificate by the server certificate. That won't work.
Install the CA certificate from my previous post. If you have a second file containing the server certificate, delete that.
Regards,
Michael