#content {padding: 0 20px;}
.helptext {font-size: 0.9em; color: #aaa; margin: 0; padding: 0;}
.description {font-size: 1.0em; color: #333;}
- a.logout, .associated, .error {color: #c00;}
+ a.logout, span.disconnect a, .error {color: #c00;}
.error {padding-left: 30px;}
#forkme {position: absolute; top: 0; right: 0;}
#valid-badges {position: absolute; right: 10px; bottom: 10px;}
<h1>Django Social Auth (v{{ version }})</h1>
<p class="description">
Django Social Auth is an easy to setup social authentication/registration mechanism for Django projects.
- Check the documentation on <a href="https://github.com/omab/django-social-auth#readme" title="docs">Github</a>
</p>
+ <p>Check the documentation on <a href="https://github.com/omab/django-social-auth#readme" title="docs">Github</a></p>
<h2 id="heading">{% block heading %}{% endblock %}</h2>
<div id="content">
<h3>Associate new OAuth credentials:</h3>
<ul>
<li>
- <a rel="nofollow" href="/associate/twitter/">Twitter</a>
- {% if twitter %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "twitter" %}">Twitter</a>
+ {% if twitter %}<span class="disconnect">(<a href="{% url disconnect "twitter" %}">disconnect</a>)</span>{% endif %}
</li>
<li>
- <a rel="nofollow" href="/associate/facebook/">Facebook</a>
- {% if facebook %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "facebook" %}">Facebook</a>
+ {% if facebook %}<span class="disconnect">(<a href="{% url disconnect "facebook" %}">disconnect</a>)</span>{% endif %}
</li>
<li>
- <a rel="nofollow" href="/associate/orkut/">Orkut</a>
- {% if orkut %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "orkut" %}">Orkut</a>
+ {% if orkut %}<span class="disconnect">(<a href="{% url disconnect "orkut" %}">disconnect</a>)</span>{% endif %}
</li>
<li>
- <a rel="nofollow" href="/associate/google-oauth/">Google</a>
- {% if google_oauth %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "google-oauth" %}">Google</a>
+ {% if google_oauth %}<span class="disconnect">(<a href="{% url disconnect "google-oauth" %}">disconnect</a>)</span>{% endif %}
</li>
</ul>
<h3>Associate new OpenID credentials:</h3>
<ul>
<li>
- <a rel="nofollow" href="/associate/google/">Google</a>
- {% if google %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "google" %}">Google</a>
+ {% if google %}<span class="disconnect">(<a href="{% url disconnect "google" %}">disconnect</a>)</span>{% endif %}
</li>
<li>
- <a rel="nofollow" href="/associate/yahoo/">Yahoo</a>
- {% if yahoo %}<span class="associated">(associated)</span>{% endif %}
+ <a rel="nofollow" href="{% url associate_begin "yahoo" %}">Yahoo</a>
+ {% if yahoo %}<span class="disconnect">(<a href="{% url disconnect "yahoo" %}">disconnect</a>)</span>{% endif %}
</li>
<li>
- <form action="/login/livejournal/" method="post">{% csrf_token %}
+ <form action="{% url associate_begin "livejournal" %}" method="post">{% csrf_token %}
<div>
<label for="openid_lj_user">LiveJournal user
- {% if livejournal %} <span class="associated">(associated)</span>{% endif %}:
+ {% if livejournal %}(<span class="disconnect"><a href="{% url disconnect "livejournal" %}">disconnect</a>)</span>{% endif %}
</label>
<input id="openid_lj_user" type="text" value="" name="openid_lj_user" />
<input type="submit" value="Login"/>
</form>
</li>
<li>
- <form action="/associate/openid/" method="post">{% csrf_token %}
+ <form action="{% url associate_begin "openid" %}" method="post">{% csrf_token %}
<div>
<label for="openid_identifier">Other provider:</label>
<input id="openid_identifier" type="text" value="" name="openid_identifier" />
<div>
<h3>Login using <a href="http://oauth.net/" title="OAuth">OAuth</a> from:</h3>
<ul>
- <li><a rel="nofollow" href="/login/twitter/">Twitter</a></li>
- <li><a rel="nofollow" href="/login/facebook/">Facebook</a></li>
- <li><a rel="nofollow" href="/login/orkut/">Orkut</a></li>
- <li><a rel="nofollow" href="/login/google-oauth/">Google OAuth</a></li>
+ <li><a rel="nofollow" href="{% url begin "twitter" %}">Twitter</a></li>
+ <li><a rel="nofollow" href="{% url begin "facebook" %}">Facebook</a></li>
+ <li><a rel="nofollow" href="{% url begin "orkut" %}">Orkut</a></li>
+ <li><a rel="nofollow" href="{% url begin "google-oauth" %}">Google OAuth</a></li>
</ul>
</div>
<div>
<h3>Login using <a href="http://openid.net/" title="OpenId">OpenId</a> from:</h3>
<ul>
- <li><a rel="nofollow" href="/login/google/">Google</a></li>
- <li><a rel="nofollow" href="/login/yahoo/">Yahoo</a></li>
+ <li><a rel="nofollow" href="{% url begin "google" %}">Google</a></li>
+ <li><a rel="nofollow" href="{% url begin "yahoo" %}">Yahoo</a></li>
<li>
- <form action="/login/livejournal/" method="post">{% csrf_token %}
+ <form action="{% url begin "livejournal" %}" method="post">{% csrf_token %}
<div>
<label for="openid_lj_user">LiveJournal user:</label>
<input id="openid_lj_user" type="text" value="" name="openid_lj_user" />
</form>
</li>
<li>
- <form action="/login/openid/" method="post">{% csrf_token %}
+ <form action="{% url begin "openid" %}" method="post">{% csrf_token %}
<div>
<label for="openid_identifier">Other provider</label>
<input id="openid_identifier" type="text" value="" name="openid_identifier" />
"""Return backend enabled status, all enabled by default"""
return True
+ def disconnect(self, user):
+ """Deletes current backend from user if associated.
+ Override if extra operations are needed.
+ """
+ user.social_auth.filter(provider=self.AUTH_BACKEND.name).delete()
+
class OpenIdAuth(BaseAuth):
"""
User screen name is used to generate username.
"""
-from django.conf import settings
from django.utils import simplejson
from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
"""URLs module"""
from django.conf.urls.defaults import patterns, url
-from social_auth.views import auth, complete, associate, associate_complete
+from social_auth.views import auth, complete, associate, associate_complete, \
+ disconnect
urlpatterns = patterns('',
url(r'^associate/(?P<backend>[^/]+)/$', associate, name='associate_begin'),
url(r'^associate/complete/(?P<backend>[^/]+)/$', associate_complete,
name='associate_complete'),
+ url(r'^disconnect/(?P<backend>[^/]+)/$', disconnect, name='disconnect'),
)
return HttpResponseRedirect(url)
+@login_required
+def disconnect(request, backend):
+ """Disconnects given backend from current logged in user."""
+ backend = get_backend(backend, request, request.path)
+ if not backend:
+ return HttpResponseServerError('Incorrect authentication service')
+ backend.disconnect(request.user)
+ url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or \
+ getattr(settings, 'LOGIN_REDIRECT_URL', '')
+ return HttpResponseRedirect(url)
+
+
def auth_process(request, backend, complete_url_name, default_final_url):
"""Authenticate using social backend"""
redirect = reverse(complete_url_name, args=(backend,))
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
- data = request.GET if request.method == 'GET' else request.POST
+ data = request.REQUEST
request.session[REDIRECT_FIELD_NAME] = data.get(REDIRECT_FIELD_NAME,
default_final_url)
if backend.uses_redirect: