Get end-to-end configuration setup working, including verification (except for Github, which is in progress)

This commit is contained in:
Joseph Schorr 2015-01-07 16:20:51 -05:00
parent 825455ea6c
commit 63504c87fb
14 changed files with 611 additions and 206 deletions

View file

@ -1,9 +1,9 @@
import urlparse
class OAuthConfig(object):
def __init__(self, app, key_name):
def __init__(self, config, key_name):
self.key_name = key_name
self.config = app.config.get(key_name) or {}
self.config = config.get(key_name) or {}
def service_name(self):
raise NotImplementedError
@ -23,6 +23,9 @@ class OAuthConfig(object):
def client_secret(self):
return self.config.get('CLIENT_SECRET')
def basic_scope(self):
raise NotImplementedError
def _get_url(self, endpoint, *args):
for arg in args:
endpoint = urlparse.urljoin(endpoint, arg)
@ -31,8 +34,8 @@ class OAuthConfig(object):
class GithubOAuthConfig(OAuthConfig):
def __init__(self, app, key_name):
super(GithubOAuthConfig, self).__init__(app, key_name)
def __init__(self, config, key_name):
super(GithubOAuthConfig, self).__init__(config, key_name)
def service_name(self):
return 'GitHub'
@ -43,6 +46,9 @@ class GithubOAuthConfig(OAuthConfig):
endpoint = endpoint + '/'
return endpoint
def basic_scope(self):
return 'user:email'
def authorize_endpoint(self):
return self._get_url(self._endpoint(), '/login/oauth/authorize') + '?'
@ -73,12 +79,15 @@ class GithubOAuthConfig(OAuthConfig):
class GoogleOAuthConfig(OAuthConfig):
def __init__(self, app, key_name):
super(GoogleOAuthConfig, self).__init__(app, key_name)
def __init__(self, config, key_name):
super(GoogleOAuthConfig, self).__init__(config, key_name)
def service_name(self):
return 'Google'
def basic_scope(self):
return 'openid email'
def authorize_endpoint(self):
return 'https://accounts.google.com/o/oauth2/auth?response_type=code&'