diff --git a/realms/modules/auth/oauth/models.py b/realms/modules/auth/oauth/models.py
index 82e1afe..46a07ba 100644
--- a/realms/modules/auth/oauth/models.py
+++ b/realms/modules/auth/oauth/models.py
@@ -18,6 +18,7 @@ providers = {
access_token_method='GET'),
'button': ' Twitter',
'field_map': {
+ 'id': 'user_id',
'username': 'screen_name'
}
},
@@ -29,7 +30,12 @@ providers = {
access_token_method='POST',
access_token_url='https://github.com/login/oauth/access_token',
authorize_url='https://github.com/login/oauth/authorize'),
- 'button': ' Github'
+ 'button': ' Github',
+ 'field_map': {
+ 'id': ['user', 'id'],
+ 'username': ['user', 'login'],
+ 'email': ['user', 'email']
+ }
},
'facebook': {
'oauth': dict(
@@ -40,7 +46,12 @@ providers = {
access_token_method='GET',
authorize_url='https://www.facebook.com/dialog/oauth'
),
- 'button': ' Facebook'
+ 'button': ' Facebook',
+ 'field_map': {
+ 'id': 'id',
+ 'username': 'name',
+ 'email': 'email'
+ }
},
'google': {
'oauth': dict(
@@ -62,10 +73,10 @@ class User(BaseUser):
type = 'oauth'
provider = None
- def __init__(self, provider, username, token):
+ def __init__(self, provider, user_id, username, token):
self.provider = provider
self.username = username
- self.id = username
+ self.id = user_id
self.token = token
self.auth_id = "%s-%s" % (provider, username)
@@ -87,11 +98,22 @@ class User(BaseUser):
if not field_map:
raise NotImplementedError
+ def get_value(d, key):
+ if isinstance(key, basestring):
+ return d.get(key)
+ # key should be list here
+ val = d.get(key.pop(0))
+ if len(key) == 0:
+ # if empty we have our value
+ return val
+ # keep digging
+ return get_value(val, key)
+
fields = {}
for k, v in field_map.items():
- fields[k] = resp[v]
+ fields[k] = get_value(resp, v)
- user = User(provider, fields['username'], User.hash_password(resp['oauth_token']))
+ user = User(provider, fields['id'], fields['username'], User.hash_password(resp['oauth_token']))
users[user.auth_id] = user
if user:
diff --git a/realms/modules/auth/oauth/views.py b/realms/modules/auth/oauth/views.py
index 5c80402..31fd281 100644
--- a/realms/modules/auth/oauth/views.py
+++ b/realms/modules/auth/oauth/views.py
@@ -11,7 +11,7 @@ def oauth_failed(next_url):
@blueprint.route("/login/oauth/")
def login(provider):
- return User.get_app(provider).authorize(callback=url_for('auth.oauth.callback', provider=provider))
+ return User.get_app(provider).authorize(callback=url_for('auth.oauth.callback', provider=provider, _external=True))
@blueprint.route('/login/oauth//callback')