1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-16 07:10:09 -07:00

Auth.from_url helper

This commit is contained in:
Adrian Sampson 2018-01-20 13:56:16 -05:00
parent 8fc2749a9b
commit 35a78281d6
2 changed files with 9 additions and 2 deletions

View File

@ -31,8 +31,7 @@ def authenticate(gateway):
print(login_url)
print('Then paste the URL where the browser is redirected:')
callback_url = input()
access_token, refresh_token = wideq.parse_oauth_callback(callback_url)
return wideq.Auth(gateway, access_token, refresh_token)
return wideq.Auth.from_url(gateway, callback_url)
def get_session(state, reauth=False):

View File

@ -157,6 +157,14 @@ class Auth(object):
self.access_token = access_token
self.refresh_token = refresh_token
@classmethod
def from_url(cls, gateway, url):
"""Create an authentication using an OAuth callback URL.
"""
access_token, refresh_token = parse_oauth_callback(url)
return cls(gateway, access_token, refresh_token)
def start_session(self):
"""Start an API session for the logged-in user. Return the
Session object and the user's devices.