Replies: 8 comments 29 replies
-
Token generation on this site works: |
Beta Was this translation helpful? Give feedback.
-
FYI for anyone looking into this, as of today 64 character code_verifier strings are no longer supported, only 86. |
Beta Was this translation helpful? Give feedback.
-
mine:
|
Beta Was this translation helpful? Give feedback.
-
The question ist what does the "code_verifier" verify if it is just a random string... ? |
Beta Was this translation helpful? Give feedback.
-
Sure... I used the code to generate the code_verifier and the challenge from this page: This is Swift code... |
Beta Was this translation helpful? Give feedback.
-
Hi @Urkman, did you figure out what the issue was? We're encountering the same error since last week (anything to do with the big Tesla API outage?), even thought is was working fine for over a year. |
Beta Was this translation helpful? Give feedback.
-
I had to modify my PHP version: function generateRandomString($length = 10) {
$character_list = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($character_list, ceil($length/strlen($character_list)) )),1,$length);
}
function gen_challenge() {
$code_verifier = generateRandomString(86);
$code_challenge = rtrim(strtr(base64_encode(hash('sha256', $code_verifier, true)), '+/', '-_'), '=');
$state = rtrim(strtr(base64_encode(generateRandomString(12)), '+/', '-_'), '=');
return array("code_verifier" => $code_verifier, "code_challenge" => $code_challenge, "state" => $state);
} Seems like we need to use byte output from the hash function. In PHP you have to pass |
Beta Was this translation helpful? Give feedback.
-
Something weird here that could help others: in debugging this issue we found that our app was re-hashing the verifier before sending it with the code grant to obtain an access token. I have no idea why it was implemented that way, but it was working just fine previously. It's most definitely out of spec for PKCE, though. Either Tesla was ignoring the verifier, or they had a really weird implementation of PKCE. Now we send the raw verifier, as per the PKCE spec, and all seems to work as expected. The minimum required verifier length is 43, as expected. Note that the verifier length is measured as sent in the URL param. This is not a byte length that is then urlsafe base64 encoded: it is the final string length. The method by which the verifier is generated is not covered in the spec. The important thing is that it must be >= 43 characters long and contain only the specified characters (which happens to be very easy to achieve with urlsafe base64 encoding, with a bit of maths to get the right length). PKCE verifier spec: |
Beta Was this translation helpful? Give feedback.
-
Hello,
the login to the Tesla API is broken since today.
We get this error:
{"error":"invalid_request","error_description":"Invalid code_verifier","error_uri":"https://auth.tesla.com/error/reference/1d9f8f73-8335-40b1-ad8b-e6d23ce673e8-1676459376419"}
This seems to be broken for everybody:
tomhollander/TeslaAuth#30
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions