[damned-lies] Refs #73 - Add GNOME OpenID login through python-social-auth



commit 50c63c1c746daa5ebff1fef1f29e12aa73631449
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue Mar 27 20:32:14 2018 +0200

    Refs #73 - Add GNOME OpenID login through python-social-auth
    
    Login link limited to the /login page for now.

 common/backends.py     |  7 +++++++
 damnedlies/settings.py | 21 +++++++++++++++++++++
 damnedlies/urls.py     |  1 +
 requirements.txt       |  1 +
 templates/login.html   |  5 +++++
 5 files changed, 35 insertions(+)
---
diff --git a/common/backends.py b/common/backends.py
new file mode 100644
index 00000000..8a8950d0
--- /dev/null
+++ b/common/backends.py
@@ -0,0 +1,7 @@
+from social_core.backends.open_id import OpenIdAuth
+
+
+class GNOMEOpenId(OpenIdAuth):
+    """GNOME OpenID authentication backend"""
+    name = 'gnome'
+    URL = 'https://id.gnome.org'
diff --git a/damnedlies/settings.py b/damnedlies/settings.py
index 5333020a..be46efbe 100644
--- a/damnedlies/settings.py
+++ b/damnedlies/settings.py
@@ -137,6 +137,7 @@ INSTALLED_APPS = [
     'django.contrib.humanize',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'social_django',
     'common',
     'languages',
     'people',
@@ -146,12 +147,32 @@ INSTALLED_APPS = [
     'feeds',
 ]
 
+AUTHENTICATION_BACKENDS = [
+    'common.backends.GNOMEOpenId',
+    'django.contrib.auth.backends.ModelBackend',
+]
+
 INTERNAL_IPS=('127.0.0.1',)
 
 SITE_DOMAIN = 'l10n.gnome.org'
 
 LOGIN_REDIRECT_URL = '/'
 
+SOCIAL_AUTH_USER_MODEL = 'people.Person'
+SOCIAL_AUTH_PIPELINE = (
+    'social_core.pipeline.social_auth.social_details',
+    'social_core.pipeline.social_auth.social_uid',
+    'social_core.pipeline.social_auth.auth_allowed',
+    'social_core.pipeline.social_auth.social_user',
+    'social_core.pipeline.user.get_username',
+    # Added (not by default):
+    'social_core.pipeline.social_auth.associate_by_email',
+    'social_core.pipeline.user.create_user',
+    'social_core.pipeline.social_auth.associate_user',
+    'social_core.pipeline.social_auth.load_extra_data',
+    'social_core.pipeline.user.user_details',
+)
+
 # Members of this group can edit all team's details and change team coordinatorship
 ADMIN_GROUP = ''
 
diff --git a/damnedlies/urls.py b/damnedlies/urls.py
index 2bf30741..9b71efa5 100644
--- a/damnedlies/urls.py
+++ b/damnedlies/urls.py
@@ -75,6 +75,7 @@ urlpatterns = [
     path('i18n/', include('django.conf.urls.i18n')),
     path('admin/', admin.site.urls),
     path('rss/', include('feeds.urls')),
+    path('', include('social_django.urls', namespace='social')),
 ]
 
 urlpatterns += [
diff --git a/requirements.txt b/requirements.txt
index 7e310f76..34552923 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,7 @@
 django>=2.0
 pillow
 mysqlclient
+social-auth-app-django==3.1.0
 django-debug-toolbar
 markdown==3.0.1
 pyicu
diff --git a/templates/login.html b/templates/login.html
index d80975d8..2db1fe22 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -31,6 +31,11 @@
   </div>
 </form>
 
+<div style="margin-top: 2em;">
+    {% url 'social:begin' 'gnome' as link %}
+    {% blocktrans %}Or <a href="{{ link }}}">login with your GNOME account</a>{% endblocktrans %}
+</div>
+
 <script type="text/javascript">
 document.getElementById('id_username').focus()
 </script>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]