From 35a78281d60c311e79fdec12f472ecadc9626f53 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 20 Jan 2018 13:56:16 -0500 Subject: [PATCH] Auth.from_url helper --- example.py | 3 +-- wideq.py | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/example.py b/example.py index 9216d06..48654d3 100644 --- a/example.py +++ b/example.py @@ -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): diff --git a/wideq.py b/wideq.py index e7575c5..56eb325 100644 --- a/wideq.py +++ b/wideq.py @@ -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.