Fetch token via authorization response URL at later point in time #71
autochargetesla
started this conversation in
General
Replies: 3 comments 4 replies
|
This is currently not possible. I have to change the return type of authorization_url() from a string to a tuple that contains the url and state string, as this is required for the two-step use case to work. |
1 reply
|
This should work: import teslapy
tesla = teslapy.Tesla('elon@tesla.com')
if not tesla.authorized:
print('Use browser to login. Page Not Found will be shown at success.')
state = tesla.new_state()
url = tesla.authorization_url(state=state)
code_verifier = tesla.code_verifier
print('Open this URL: ' + url)
tesla.close()
del tesla
tesla = teslapy.Tesla('elon@tesla.com', state=state)
if not tesla.authorized:
tesla.fetch_token(authorization_response=input('Enter URL after authentication: '),
code_verifier=code_verifier)
vehicles = tesla.vehicle_list()
print(vehicles[0])
tesla.close()Does this cover your use case? |
2 replies
|
Hello @tdorssers, thank you for your previous support on answering my questions! I have a follow-up question: Cheers |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello!
Excellent work on this library !
As described in the section Alternative, the URL generated after successful Tesla login in the browser is (immediately) supplied to
authorization_response. As a result, the tokens are generated and available to TeslaPy. This works perfectly !In our use case, there will be a minor delay between these two steps. Therefore, the question is: is it possible to run TeslaPy to generate the tokens from the
authorization_responseURL independently from the first step?To summarize this two-step use case:
tesla.authorization_url(), paste URL in the browser and perform Tesla login resulting in 404 page. Copy this URL for later use.authorization_response(or elsewhere?) to generate set the of tokens (e.g. refresh token).Cheers!
All reactions