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

Is login.js returning incorrect refresh token? #262

Open
IMgoRt opened this issue Jul 23, 2021 · 8 comments · May be fixed by #220
Open

Is login.js returning incorrect refresh token? #262

IMgoRt opened this issue Jul 23, 2021 · 8 comments · May be fixed by #220
Assignees

Comments

@IMgoRt
Copy link

IMgoRt commented Jul 23, 2021

When I execute lgoin.js on my windows PC on my account with MFA enabled I get a .token returned.
However, the refresh_token within appears to be from "step 4" https://tesla-api.timdorr.com/api-basics/authentication#step-4-exchange-bearer-token-for-access-token which the API documentation indicates is of no value (in the token refresh section https://tesla-api.timdorr.com/api-basics/authentication#refreshing-an-access-token):
"This uses the SSO refresh_token from Step 3 above to do an OAuth 2.0 Refresh Token Grant. This does not work with the refresh_token provided by the Owner API. Those have no use currently and should be discarded."

and that the correct refresh_token is that from "step 3" https://tesla-api.timdorr.com/api-basics/authentication#step-3-exchange-authorization-code-for-bearer-token

The refresh_token should be in the form "refresh_token": "eyJrefresh"

Thanks

@mseminatore
Copy link
Owner

@IMgoRt Yes, you are correct. With the auth changes that Tesla made I have not yet fixed up the refresh token handling. There is a PR for this that I need to review and merge if it works. I will try to get to this soon.

@mseminatore mseminatore self-assigned this Jul 23, 2021
@mseminatore mseminatore linked a pull request Jul 23, 2021 that will close this issue
@IMgoRt
Copy link
Author

IMgoRt commented Jul 24, 2021

Thanks, that PR works for me

@IMgoRt IMgoRt closed this as completed Jul 24, 2021
@mseminatore mseminatore reopened this Jul 24, 2021
@mseminatore
Copy link
Owner

I'll close this when I complete the merge. @IMgoRt can you confirm that you test merged in the PR or did you just inspect the diff?

@IMgoRt
Copy link
Author

IMgoRt commented Jul 24, 2021

I ran the code in the PR and it returned a valid refresh_token (and all other items remained correct)

@Morgulisan
Copy link

Anything new? When will the npm be updated?

@GaPhi
Copy link
Contributor

GaPhi commented Aug 16, 2021

Another way to be compatible of many user interfaces is to add in teslaja/src/auth.js, just as the first lines of login function:

(...)
exports.login = function login(credentials, callback) {
    // Tokens as username/password when username does not contain @
    if (!credentials.identity.includes('@')) {
        callback(null, {}, { access_token: credentials.identity, refresh_token: credentials.credential });
        return;
    }

    var codeVerifier = generateCodeVerifier();
(...)

Then, provide access and refresh tokens as username/password in your preferred UI.

I also found that id_s seems to have changed; using the new one, everything is now working for me!

But the username/password is not possible yet and it would be great as getting token/refresh tokens with an external app is not very easy...

Pull request #268 created

@mluggy
Copy link

mluggy commented Aug 27, 2021

brilliant, but I would support access/refresh token natively instead of hacking them through username/password.

@mseminatore
Copy link
Owner

I am considering adding 2captcha support. Thoughts on that as a solution to keep the library headless and avoid the need to show a webview? I don't like taking a dependency on a paid service. OTOH I am struggling to find another solution that keeps this library working.

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

Successfully merging a pull request may close this issue.

5 participants