]> git.parisson.com Git - django-social-auth.git/commitdiff
Small changes to github backend doc and code. Refs #122
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 22 Aug 2011 19:24:31 +0000 (16:24 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 22 Aug 2011 19:24:31 +0000 (16:24 -0300)
README.rst
doc/backends/github.rst [new file with mode: 0644]
doc/backends/index.rst
social_auth/backends/contrib/github.py

index f9f4ca0b97514b11dfd70e025f3e0dacc3978d17..b18cfa8b592f4c8a9da96114d0bf992394106bcb 100644 (file)
@@ -526,17 +526,17 @@ way the values will be stored in ``UserSocialAuth.extra_data`` field.
 By default ``id``, ``first-name`` and ``last-name`` are requested and stored.
 
 
---------
-Github
---------
-Github works similar to Facebook (OAuth).
+------
+GitHub
+------
+GitHub works similar to Facebook (OAuth).
 
-- Register a new application at `Github Developers`_, and
+- Register a new application at `GitHub Developers`_, and
 
 - fill ``App Id`` and ``App Secret`` values in the settings::
 
-      GITHUB_APP_ID
-      GITHUB_API_SECRET
+      GITHUB_APP_ID = ''
+      GITHUB_API_SECRET = ''
 
 - also it's possible to define extra permissions with::
 
@@ -649,7 +649,7 @@ Attributions to whom deserves:
 
 - revolunet_ (Julien Bouquillon)
 
-  - Github support
+  - GitHub support
 
 ----------
 Copyrights
@@ -722,4 +722,4 @@ Base work is copyrighted by:
 .. _Read the Docs: http://django-social-auth.readthedocs.org/
 .. _revolunet: https://github.com/revolunet
 .. _GitHub OAuth: http://developer.github.com/v3/oauth/
-.. _github developers: https://github.com/account/applications/new
+.. _GitHub Developers: https://github.com/account/applications/new
diff --git a/doc/backends/github.rst b/doc/backends/github.rst
new file mode 100644 (file)
index 0000000..ea46e46
--- /dev/null
@@ -0,0 +1,17 @@
+GitHub
+======
+Github works similar to Facebook (OAuth).
+
+- Register a new application at `GitHub Developers`_, and
+
+- fill ``App Id`` and ``App Secret`` values in the settings::
+
+      GITHUB_APP_ID = ''
+      GITHUB_API_SECRET = ''
+
+- also it's possible to define extra permissions with::
+
+     GITHUB_EXTENDED_PERMISSIONS = [...]
+
+
+.. _GitHub Developers: https://github.com/account/applications/new
index d3fb25ae68b6bd7615fd11897d687cf91e434ae0..4cb8465e8642cd34c9beb0b6cac65fff8731a71b 100644 (file)
@@ -12,3 +12,4 @@ Contents:
    twitter
    facebook
    linkedin
+   github
index d53801e1e0eb35d3126546097c07dfceea1f054f..7c2e8b8056cf9c2c36c0a1dbdb993ab0db45eb56 100644 (file)
@@ -3,7 +3,7 @@ GitHub OAuth support.
 
 This contribution adds support for GitHub OAuth service. The settings
 GITHUB_APP_ID and GITHUB_API_SECRET must be defined with the values
-given by Facebook application registration process.
+given by GitHub application registration process.
 
 Extended permissions are supported by defining GITHUB_EXTENDED_PERMISSIONS
 setting, it must be a list of values to request.
@@ -20,13 +20,15 @@ from django.contrib.auth import authenticate
 
 from social_auth.backends import BaseOAuth, OAuthBackend, USERNAME
 
-# Facebook configuration
+
+# GitHub configuration
 GITHUB_SERVER = 'github.com'
 GITHUB_AUTHORIZATION_URL = 'https://%s/login/oauth/authorize' % GITHUB_SERVER
 GITHUB_ACCESS_TOKEN_URL = 'https://%s/login/oauth/access_token' % GITHUB_SERVER
 GITHUB_API_URL = 'https://api.%s' % GITHUB_SERVER
 EXPIRES_NAME = getattr(settings, 'SOCIAL_AUTH_EXPIRATION', 'expires')
 
+
 class GithubBackend(OAuthBackend):
     """Github OAuth authentication backend"""
     name = 'github'
@@ -35,11 +37,9 @@ class GithubBackend(OAuthBackend):
 
     def get_user_details(self, response):
         """Return user details from Github account"""
-        return {
-            'username':response.get('login'),
-            'email':response.get('email'),
-            'firstname':response.get('name')
-            }
+        return {USERNAME: response.get('login'),
+                'email': response.get('email'),
+                'firstname': response.get('name')}
 
 class GithubAuth(BaseOAuth):
     """Github OAuth mechanism"""
@@ -56,7 +56,6 @@ class GithubAuth(BaseOAuth):
     def auth_complete(self, *args, **kwargs):
         """Returns user, might be logged in"""
         if 'code' in self.data:
-            
             url = GITHUB_ACCESS_TOKEN_URL + '?' + \
                   urllib.urlencode({'client_id': settings.GITHUB_APP_ID,
                                 'redirect_uri': self.redirect_uri,
@@ -81,15 +80,13 @@ class GithubAuth(BaseOAuth):
 
     def user_data(self, access_token):
         """Loads user data from service"""
-        params = {'access_token': access_token,}
-        url = '%s/user' % GITHUB_API_URL + '?' + urllib.urlencode(params)
+        params = {'access_token': access_token}
+        url = GITHUB_API_URL + '/user?' + urllib.urlencode(params)
         try:
-            data = simplejson.load(urllib.urlopen(url))
-            return data
+            return simplejson.load(urllib.urlopen(url))
         except ValueError:
             return None
 
-
     @classmethod
     def enabled(cls):
         """Return backend enabled status by checking basic settings"""