Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for LinkedIn OAuth

  • Loading branch information...
commit 3f9151f5e08f66107deed5ff9e3e9aa7051baf4d 1 parent b8a0bce
@theju theju authored
View
1  AUTHORS
@@ -15,6 +15,7 @@ Ian Langworth <ian@langworth.com>
James Addison <code@scottisheyes.com>
Joeri Djojosoeparto <jsoejitno@gmail.com>
Joseph Bergantine <jbergantine@gmail.com>
+Thejaswi Puthraya <thejaswi.puthraya@gmail.com>
Tobias Hasselrot <tobias.hasselrot@gmail.com>
Tom Drummond <tom@devioustree.co.uk>
Zellyn Hunter <Zellyn.Hunter@cmgdigital.com>
View
29 README.md
@@ -108,6 +108,35 @@ Supported methods currently are:
{% twitter_button 'http://example.com/other_twitter_button.png' %}
+## LinkedIn
+
+#### Configuration
+
+1. Add the LinkedIn API keys and endpoints to your settings, variable names are
+
+ LINKEDIN_CONSUMER_KEY = ''
+ LINKEDIN_CONSUMER_SECRET_KEY = ''
+ LINKEDIN_REQUEST_TOKEN_URL = ''
+ LINKEDIN_ACCESS_TOKEN_URL = ''
+ LINKEDIN_AUTHORIZATION_URL = ''
+
+2. Add `socialregistration.auth.LinkedInAuth` to `AUTHENTICATION_BACKENDS`
+3. Add the right callback URL to your LinkedIn account
+
+#### Usage
+
+* Add tags to your template file
+
+ {% load linkedin_tags %}
+ {% linkedin_button %}
+
+ Same note here. Make sure you're serving the page with a `RequestContext`
+
+ You can also specify your own custom button image by appending it to the `linkedin_button` template tag:
+
+ {% linkedin_button 'http://example.com/other_linkedin_button.png' %}
+
+
## OAuth
Check out how the Twitter authentication works. Basically it's just plugging
View
41 README.rst
@@ -146,6 +146,47 @@ You can also specify your own custom button image by appending it to the
{% twitter_button 'http://example.com/other_twitter_button.png' %}
+LinkedIn
+--------
+
+Configuration
+^^^^^^^^^^^^^
+
+1. Add the LinkedIn API keys and endpoints to your settings, variable
+ names are
+
+ ::
+
+ LINKEDIN_CONSUMER_KEY = ''
+ LINKEDIN_CONSUMER_SECRET_KEY = ''
+ LINKEDIN_REQUEST_TOKEN_URL = ''
+ LINKEDIN_ACCESS_TOKEN_URL = ''
+ LINKEDIN_AUTHORIZATION_URL = ''
+
+2. Add ``socialregistration.auth.LinkedInAuth`` to
+ ``AUTHENTICATION_BACKENDS``
+3. Add the right callback URL to your LinkedIn account
+
+Usage
+^^^^^
+
+- Add tags to your template file
+
+ ::
+
+ {% load linkedin_tags %}
+ {% linkedin_button %}
+
+Same note here. Make sure you're serving the page with a
+``RequestContext``
+
+You can also specify your own custom button image by appending it to the
+``linkedin_button`` template tag:
+
+::
+
+ {% linkedin_button 'http://example.com/other_linkedin_button.png' %}
+
OAuth
-----
View
5 socialregistration/admin.py
@@ -1,7 +1,8 @@
from django.contrib import admin
from socialregistration.models import (FacebookProfile, TwitterProfile,
- OpenIDProfile, OpenIDStore, OpenIDNonce)
+ OpenIDProfile, OpenIDStore, OpenIDNonce, LinkedInProfile)
-admin.site.register([FacebookProfile, TwitterProfile, OpenIDProfile, OpenIDStore, OpenIDNonce])
+admin.site.register([FacebookProfile, TwitterProfile, LinkedInProfile,
+ OpenIDProfile, OpenIDStore, OpenIDNonce])
View
13 socialregistration/auth.py
@@ -1,7 +1,8 @@
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
-from socialregistration.models import (FacebookProfile, TwitterProfile, OpenIDProfile)
+from socialregistration.models import (FacebookProfile, TwitterProfile,
+ OpenIDProfile, LinkedInProfile)
class Auth(object):
supports_object_permissions = False
@@ -32,6 +33,16 @@ def authenticate(self, twitter_id=None):
except TwitterProfile.DoesNotExist:
return None
+class LinkedInAuth(Auth):
+ def authenticate(self, linkedin_id=None):
+ try:
+ return LinkedInProfile.objects.get(
+ linkedin_id=linkedin_id,
+ site=Site.objects.get_current()
+ ).user
+ except LinkedInProfile.DoesNotExist:
+ return None
+
class OpenIDAuth(Auth):
def authenticate(self, identity=None):
try:
View
177 ...migrations/0004_auto__add_linkedinprofile__add_linkedinrequesttoken__add_linkedinacces.py
@@ -0,0 +1,177 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'LinkedInProfile'
+ db.create_table('socialregistration_linkedinprofile', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True)),
+ ('site', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])),
+ ('linkedin_id', self.gf('django.db.models.fields.CharField')(max_length=25)),
+ ))
+ db.send_create_signal('socialregistration', ['LinkedInProfile'])
+
+ # Adding model 'LinkedInRequestToken'
+ db.create_table('socialregistration_linkedinrequesttoken', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('profile', self.gf('django.db.models.fields.related.OneToOneField')(related_name='request_token', unique=True, to=orm['socialregistration.LinkedInProfile'])),
+ ('oauth_token', self.gf('django.db.models.fields.CharField')(max_length=80)),
+ ('oauth_token_secret', self.gf('django.db.models.fields.CharField')(max_length=80)),
+ ))
+ db.send_create_signal('socialregistration', ['LinkedInRequestToken'])
+
+ # Adding model 'LinkedInAccessToken'
+ db.create_table('socialregistration_linkedinaccesstoken', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('profile', self.gf('django.db.models.fields.related.OneToOneField')(related_name='access_token', unique=True, to=orm['socialregistration.LinkedInProfile'])),
+ ('oauth_token', self.gf('django.db.models.fields.CharField')(max_length=80)),
+ ('oauth_token_secret', self.gf('django.db.models.fields.CharField')(max_length=80)),
+ ))
+ db.send_create_signal('socialregistration', ['LinkedInAccessToken'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'LinkedInProfile'
+ db.delete_table('socialregistration_linkedinprofile')
+
+ # Deleting model 'LinkedInRequestToken'
+ db.delete_table('socialregistration_linkedinrequesttoken')
+
+ # Deleting model 'LinkedInAccessToken'
+ db.delete_table('socialregistration_linkedinaccesstoken')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'socialregistration.facebookaccesstoken': {
+ 'Meta': {'object_name': 'FacebookAccessToken'},
+ 'access_token': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'profile': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'access_token'", 'unique': 'True', 'to': "orm['socialregistration.FacebookProfile']"})
+ },
+ 'socialregistration.facebookprofile': {
+ 'Meta': {'object_name': 'FacebookProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'uid': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ },
+ 'socialregistration.linkedinaccesstoken': {
+ 'Meta': {'object_name': 'LinkedInAccessToken'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'oauth_token': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'oauth_token_secret': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'profile': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'access_token'", 'unique': 'True', 'to': "orm['socialregistration.LinkedInProfile']"})
+ },
+ 'socialregistration.linkedinprofile': {
+ 'Meta': {'object_name': 'LinkedInProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'linkedin_id': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ },
+ 'socialregistration.linkedinrequesttoken': {
+ 'Meta': {'object_name': 'LinkedInRequestToken'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'oauth_token': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'oauth_token_secret': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'profile': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'request_token'", 'unique': 'True', 'to': "orm['socialregistration.LinkedInProfile']"})
+ },
+ 'socialregistration.openidnonce': {
+ 'Meta': {'object_name': 'OpenIDNonce'},
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'salt': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'server_url': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'timestamp': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'socialregistration.openidprofile': {
+ 'Meta': {'object_name': 'OpenIDProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identity': ('django.db.models.fields.TextField', [], {}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ },
+ 'socialregistration.openidstore': {
+ 'Meta': {'object_name': 'OpenIDStore'},
+ 'assoc_type': ('django.db.models.fields.TextField', [], {}),
+ 'handle': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'issued': ('django.db.models.fields.IntegerField', [], {}),
+ 'lifetime': ('django.db.models.fields.IntegerField', [], {}),
+ 'secret': ('django.db.models.fields.TextField', [], {}),
+ 'server_url': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'socialregistration.twitteraccesstoken': {
+ 'Meta': {'object_name': 'TwitterAccessToken'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'oauth_token': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'oauth_token_secret': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'profile': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'access_token'", 'unique': 'True', 'to': "orm['socialregistration.TwitterProfile']"})
+ },
+ 'socialregistration.twitterprofile': {
+ 'Meta': {'object_name': 'TwitterProfile'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'twitter_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ },
+ 'socialregistration.twitterrequesttoken': {
+ 'Meta': {'object_name': 'TwitterRequestToken'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'oauth_token': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'oauth_token_secret': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+ 'profile': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'request_token'", 'unique': 'True', 'to': "orm['socialregistration.TwitterProfile']"})
+ }
+ }
+
+ complete_apps = ['socialregistration']
View
44 socialregistration/models.py
@@ -49,6 +49,30 @@ class TwitterAccessToken(models.Model):
oauth_token = models.CharField(max_length=80)
oauth_token_secret = models.CharField(max_length=80)
+class LinkedInProfile(models.Model):
+ user = models.ForeignKey(User, unique = True)
+ site = models.ForeignKey(Site, default=Site.objects.get_current)
+ linkedin_id = models.CharField(max_length=25)
+
+ def __unicode__(self):
+ try:
+ return u'%s: %s' % (self.user, self.linkedin_id)
+ except User.DoesNotExist:
+ return u'None'
+
+ def authenticate(self):
+ return authenticate(linkedin_id=self.linkedin_id)
+
+class LinkedInRequestToken(models.Model):
+ profile = models.OneToOneField(LinkedInProfile,related_name='request_token')
+ oauth_token = models.CharField(max_length=80)
+ oauth_token_secret = models.CharField(max_length=80)
+
+class LinkedInAccessToken(models.Model):
+ profile = models.OneToOneField(LinkedInProfile,related_name='access_token')
+ oauth_token = models.CharField(max_length=80)
+ oauth_token_secret = models.CharField(max_length=80)
+
class OpenIDProfile(models.Model):
user = models.ForeignKey(User, unique = True)
site = models.ForeignKey(Site, default=Site.objects.get_current)
@@ -114,7 +138,27 @@ def save_twitter_token(sender, user, profile, client, **kwargs):
oauth_token = client.access_token['oauth_token'],
oauth_token_secret = client.access_token['oauth_token_secret'])
+def save_linkedin_token(sender, user, profile, client, **kwargs):
+ try:
+ LinkedInRequestToken.objects.get(profile=profile).delete()
+ except LinkedInRequestToken.DoesNotExist:
+ pass
+ try:
+ LinkedInAccessToken.objects.get(profile=profile).delete()
+ except LinkedInAccessToken.DoesNotExist:
+ pass
+
+ LinkedInRequestToken.objects.create(profile=profile,
+ oauth_token = client.request_token['oauth_token'],
+ oauth_token_secret = client.request_token['oauth_token_secret'])
+
+ LinkedInAccessToken.objects.create(profile=profile,
+ oauth_token = client.access_token['oauth_token'],
+ oauth_token_secret = client.access_token['oauth_token_secret'])
+
connect.connect(save_facebook_token, sender = FacebookProfile,
dispatch_uid = 'socialregistration_facebook_token')
connect.connect(save_twitter_token, sender = TwitterProfile,
dispatch_uid = 'socialregistration_twitter_token')
+connect.connect(save_linkedin_token, sender = LinkedInProfile,
+ dispatch_uid = 'socialregistration_linkedin_token')
View
8 socialregistration/templates/socialregistration/linkedin_button.html
@@ -0,0 +1,8 @@
+{% load linkedin_tags socialregistration_tags %}
+<form class="connect-button" name="login" method="post" action="{% url linkedin_redirect %}">
+{% social_csrf_token %}
+{% if next %}
+ <input type="hidden" name="next" value="{{ next }}" />
+{% endif %}
+<input type="image" onclick="this.form.submit();" src="{% if button %}{{ button }}{% else %}http://developer.linkedin.com/sites/default/files/linkedin-small.png{% endif %}" />
+</form>
View
14 socialregistration/templatetags/linkedin_tags.py
@@ -0,0 +1,14 @@
+from django import template
+
+register = template.Library()
+
+@register.inclusion_tag('socialregistration/linkedin_button.html', takes_context=True)
+def linkedin_button(context, button=None):
+ if not 'request' in context:
+ raise AttributeError, 'Please add the ``django.core.context_processors.request`` context processors to your settings.TEMPLATE_CONTEXT_PROCESSORS set'
+ logged_in = context['request'].user.is_authenticated()
+ if 'next' in context:
+ next = context['next']
+ else:
+ next = None
+ return dict(next=next, logged_in=logged_in, button=button, request=context['request'])
View
32 socialregistration/urls.py
@@ -7,7 +7,7 @@
from django.conf import settings
from django.conf.urls.defaults import *
-from socialregistration.utils import OpenID, OAuthClient, OAuthTwitter
+from socialregistration.utils import OpenID, OAuthClient, OAuthTwitter, OAuthLinkedIn
urlpatterns = patterns('',
@@ -62,6 +62,36 @@
url('^twitter/$', 'socialregistration.views.twitter', {'client_class': OAuthTwitter}, name='twitter'),
)
+#Setup LinkedIn URLs if there's an API key specified
+if getattr(settings, 'LINKEDIN_CONSUMER_KEY', None) is not None:
+ urlpatterns = urlpatterns + patterns('',
+ url('^linkedin/redirect/$', 'socialregistration.views.oauth_redirect',
+ dict(
+ consumer_key=settings.LINKEDIN_CONSUMER_KEY,
+ secret_key=settings.LINKEDIN_CONSUMER_SECRET_KEY,
+ request_token_url=settings.LINKEDIN_REQUEST_TOKEN_URL,
+ access_token_url=settings.LINKEDIN_ACCESS_TOKEN_URL,
+ authorization_url=settings.LINKEDIN_AUTHORIZATION_URL,
+ callback_url='linkedin_callback',
+ client_class = OAuthClient
+ ),
+ name='linkedin_redirect'),
+
+ url('^linkedin/callback/$', 'socialregistration.views.oauth_callback',
+ dict(
+ consumer_key=settings.LINKEDIN_CONSUMER_KEY,
+ secret_key=settings.LINKEDIN_CONSUMER_SECRET_KEY,
+ request_token_url=settings.LINKEDIN_REQUEST_TOKEN_URL,
+ access_token_url=settings.LINKEDIN_ACCESS_TOKEN_URL,
+ authorization_url=settings.LINKEDIN_AUTHORIZATION_URL,
+ callback_url='linkedin',
+ client_class = OAuthClient
+ ),
+ name='linkedin_callback'
+ ),
+ url('^linkedin/$', 'socialregistration.views.linkedin', {'client_class': OAuthLinkedIn}, name='linkedin'),
+ )
+
urlpatterns = urlpatterns + patterns('',
url('^openid/redirect/$', 'socialregistration.views.openid_redirect', { 'client_class': OpenID}, name='openid_redirect'),
url('^openid/callback/$', 'socialregistration.views.openid_callback', { 'client_class': OpenID}, name='openid_callback')
View
6 socialregistration/utils.py
@@ -343,3 +343,9 @@ class OAuthTwitter(OAuth):
def get_user_info(self):
user = simplejson.loads(self.query(self.url))
return user
+
+class OAuthLinkedIn(OAuthTwitter):
+ """
+ Verifying linkedin credentials
+ """
+ url = "http://api.linkedin.com/v1/people/~:(id)?format=json"
View
51 socialregistration/views.py
@@ -20,7 +20,7 @@
from socialregistration.forms import UserForm
from socialregistration.utils import (OAuthClient, OAuthTwitter,
OpenID, _https, DiscoveryFailure)
-from socialregistration.models import FacebookProfile, TwitterProfile, OpenIDProfile
+from socialregistration.models import FacebookProfile, TwitterProfile, LinkedInProfile, OpenIDProfile
from socialregistration import signals
@@ -232,6 +232,55 @@ def twitter(request, account_inactive_template='socialregistration/account_inact
return HttpResponseRedirect(_get_next(request))
+
+def linkedin(request, account_inactive_template='socialregistration/account_inactive.html',
+ extra_context=dict(), client_class=None):
+ """
+ Actually setup/login an account relating to a linkedin user after the oauth
+ process is finished successfully
+ """
+ client = client_class(
+ request, settings.LINKEDIN_CONSUMER_KEY,
+ settings.LINKEDIN_CONSUMER_SECRET_KEY,
+ settings.LINKEDIN_REQUEST_TOKEN_URL,
+ )
+
+ user_info = client.get_user_info()
+
+ if request.user.is_authenticated():
+ # Handling already logged in users connecting their accounts
+ try:
+ profile = LinkedInProfile.objects.get(linkedin_id=user_info['id'])
+ except LinkedInProfile.DoesNotExist: # There can only be one profile!
+ profile = LinkedInProfile.objects.create(user=request.user, linkedin_id=user_info['id'])
+ _connect(request.user, profile, client)
+
+ return HttpResponseRedirect(_get_next(request))
+
+ user = authenticate(linkedin_id=user_info['id'])
+
+ if user is None:
+ profile = LinkedInProfile(linkedin_id=user_info['id'])
+ user = User()
+ request.session['socialregistration_profile'] = profile
+ request.session['socialregistration_user'] = user
+ # Client is not pickleable with the request on it
+ client.request = None
+ request.session['socialregistration_client'] = client
+ request.session['next'] = _get_next(request)
+ return HttpResponseRedirect(reverse('socialregistration_setup'))
+
+ if not user.is_active:
+ return render_to_response(
+ account_inactive_template,
+ extra_context,
+ context_instance=RequestContext(request)
+ )
+
+ _login(request, user, LinkedInProfile.objects.get(user = user), client)
+
+ return HttpResponseRedirect(_get_next(request))
+
def oauth_redirect(request, consumer_key=None, secret_key=None,
request_token_url=None, access_token_url=None, authorization_url=None,
callback_url=None, parameters=None, client_class = None):
Please sign in to comment.
Something went wrong with that request. Please try again.