change github fieldmap

define tokengetter for each provider
This commit is contained in:
Matthew Scragg 2015-11-13 17:25:55 -06:00
parent 027abd0658
commit 1e62997272
2 changed files with 7 additions and 5 deletions

View file

@ -36,9 +36,9 @@ providers = {
'button': '<a href="/login/oauth/github" class="btn btn-default"><i class="fa fa-github"></i> Github</a>', 'button': '<a href="/login/oauth/github" class="btn btn-default"><i class="fa fa-github"></i> Github</a>',
'profile': 'user', 'profile': 'user',
'field_map': { 'field_map': {
'id': ['user', 'id'], 'id': 'id',
'username': ['user', 'login'], 'username': 'login',
'email': ['user', 'email'] 'email': 'email'
}, },
'token_name': 'access_token' 'token_name': 'access_token'
}, },
@ -141,12 +141,14 @@ class User(BaseUser):
def get_app(cls, provider): def get_app(cls, provider):
if oauth.remote_apps.get(provider): if oauth.remote_apps.get(provider):
return oauth.remote_apps.get(provider) return oauth.remote_apps.get(provider)
return oauth.remote_app( app = oauth.remote_app(
provider, provider,
consumer_key=config.OAUTH.get(provider, {}).get('key'), consumer_key=config.OAUTH.get(provider, {}).get('key'),
consumer_secret=config.OAUTH.get(provider, {}).get( consumer_secret=config.OAUTH.get(provider, {}).get(
'secret'), 'secret'),
**providers[provider]['oauth']) **providers[provider]['oauth'])
app.tokengetter(lambda: session.get(provider + "_token"))
return app
@classmethod @classmethod
def get_provider_value(cls, provider, key): def get_provider_value(cls, provider, key):

View file

@ -32,7 +32,7 @@ def callback(provider):
oauth_token = resp.get(User.get_provider_value(provider, 'token_name')) oauth_token = resp.get(User.get_provider_value(provider, 'token_name'))
session[provider + "_token"] = (oauth_token, '') session[provider + "_token"] = (oauth_token, '')
profile = User.get_provider_value(provider, 'profile') profile = User.get_provider_value(provider, 'profile')
data = remote_app.get(profile) if profile else resp data = remote_app.get(profile).data if profile else resp
User.auth(provider, data, oauth_token) User.auth(provider, data, oauth_token)