Step2 get 403 error #614
Replies: 6 comments 2 replies
-
I have the same problem. Tried "everything". If anyone who sees this and doesn't have the problem could perhaps post exactly what their post request looks like, it'd be much appreciated. I don't know if I'm formatting the body correctly, the documentation just says there should be a String[] with the hidden input values but that could be interpreted in a bunch of different ways..? |
Beta Was this translation helpful? Give feedback.
-
@ben25belot maybe you could try to change |
Beta Was this translation helpful? Give feedback.
-
@ben25belot @emilfors |
Beta Was this translation helpful? Give feedback.
-
I have the same problem with my python implementation so I tried to use the ruby lib. I was pretty supprised when it also threw the 403. From looking at traffic generated by token creators like Chromium Tesla Token Generator. I found out that their hash for the code challenge is a lot shorter then the one created by this implementation. I don't know if that is the problem. I'm also not quite sure if I set up my Ruby implementation correctly, I think I followed the example given. |
Beta Was this translation helpful? Give feedback.
-
This one stumped me along with everyone else. What I found is bizarre. Long story short, a Node.js implementation is working, but a PHP implementation fails. What?! Can anyone explain how? The implementation is the same down the characters chosen (I THINK). As soon as I go to trade the So AkamaiGHost is blocking PHP cURL requests somehow? I have no idea how this could happen, but maybe I'm too close to the problem and the Node.js and PHP implementations are not truly the same.. Node.js: function bufferBase64url(buffer) {
return buffer.toString("base64").replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
}
// Generate a random state identifier string (10 bytes = 16 characters)
const state = bufferBase64url(crypto.randomBytes(10));
// Generate a random code verifier string (64 bytes = 86 characters)
const codeVerifier = bufferBase64url(crypto.randomBytes(64));
// SHA-256 hash the codeVerifier string
const hash = crypto.createHash("sha256").update(codeVerifier).digest();
const codeChallenge = bufferBase64url(Buffer.from(hash));
// click the URL in the browser, decode the resulting Tesla URL, land here to trade in the code for an access token
let url = `https://auth.tesla.com/oauth2/v3/token`;
const res = await request(
url,
{
method: "POST",
headers: { "Content-Type": "application/json" }
}, JSON.stringify({
grant_type: "authorization_code",
client_id: "ownerapi",
code,
codeVerifier,
redirect_uri: `https://auth.tesla.com/void/callback`
})
);
const token = JSON.parse(res.body);
token.issuer = issuer;
return token;
// Response: Tokens!!! PHP: public function base64UrlEncode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
// Generate a random state identifier string (10 bytes = 16 characters)
$state = $this->base64UrlEncode(random_bytes(10));
// Generate a random code verifier string (64 bytes = 86 characters)
$codeVerifier = $this->base64UrlEncode(random_bytes(64));
// SHA-256 hash the codeVerifier string
$hash = hash("sha256", $codeVerifier, true);
$codeChallenge = $this->base64UrlEncode($hash);
// click the URL in the browser, decode the resulting Tesla URL, land here to trade in the code for an access token
$ch = curl_init("https://auth.tesla.com/oauth2/v3/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"grant_type" => "authorization_code",
"client_id" => "ownerapi",
"code_verifier" => $codeVerifier,
"code" => $code,
"redirect_uri" => "https://auth.tesla.com/void/callback"
]));
curl_setopt($ch, CURLOPT_HEADER, true);
/*curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Accept-Encoding: gzip, deflate, br"
]);*/
$response = curl_exec($ch);
Log::info($response);
curl_close($ch);
// Response: Access Denied - AkamaiGHost |
Beta Was this translation helpful? Give feedback.
-
I don't have an answer but the docs are a bit unclear around the "set-cookie header" since there are multiple "Set-Cookie" headers in the response. For the OP they picked just one (tesla-auth.sid) but in a network trace I see multiple "Set-Cookie" headers being echo'd back in the post request. I tried providing them all in the cookie header but that didnt help the 403 problem. I don't think it has anything to do with the code challenge as step 2 is not yet at a stage for verification (seems to happen in step 3) For hidden values I wasnt sure of the notation, I did this:
That gets me to a application/x-www-form-urlencode format for the body with the hidden values. Anyway i'm stuck too and have tried a few things but something is missing. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
Could you help me ?
I would like to implement this api in Python. I did the first step easily and I get the set-cookie and hidden inputs but when I construct (correctly for me) and request the second step I get a 403 error, unauthorized.
Anyone else experience this trouble ?
Here is my code :
Beta Was this translation helpful? Give feedback.
All reactions