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>',
'profile': 'user',
'field_map': {
'id': ['user', 'id'],
'username': ['user', 'login'],
'email': ['user', 'email']
'id': 'id',
'username': 'login',
'email': 'email'
},
'token_name': 'access_token'
},
@ -141,12 +141,14 @@ class User(BaseUser):
def get_app(cls, provider):
if oauth.remote_apps.get(provider):
return oauth.remote_apps.get(provider)
return oauth.remote_app(
app = oauth.remote_app(
provider,
consumer_key=config.OAUTH.get(provider, {}).get('key'),
consumer_secret=config.OAUTH.get(provider, {}).get(
'secret'),
**providers[provider]['oauth'])
app.tokengetter(lambda: session.get(provider + "_token"))
return app
@classmethod
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'))
session[provider + "_token"] = (oauth_token, '')
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)