Fetch token via authorization response URL at later point in time #71
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. |
Beta Was this translation helpful? Give feedback.
-
This should work: import teslapy
tesla = teslapy.Tesla('[email protected]')
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('[email protected]', 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? |
Beta Was this translation helpful? Give feedback.
-
Hello @tdorssers, thank you for your previous support on answering my questions! I have a follow-up question: Cheers |
Beta Was this translation helpful? Give feedback.
-
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_response
URL 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!
Beta Was this translation helpful? Give feedback.
All reactions