You can use the ska package, which implements login without entering Django without a password. ska works with authentication tokens, and its security is based on SHARED_KEY, which should be the same for all parties involved (servers).
On the client side (the side that requests a login without a password), you generate a URL and sign it using ska . Example:
from ska import sign_url from ska.contrib.django.ska.settings import SECRET_KEY server_ska_login_url = 'https://server-url.com/ska/login/' signed_url = sign_url( auth_user='test_ska_user_0', secret_key=SECRET_KEY, url=server_ska_login_url extra={ 'email': 'john.doe@mail.example.com', 'first_name': 'John', 'last_name': 'Doe', } )
The default token expiration time is 600 seconds. You can tweak this by proving a lifetime argument.
On the server side (the site where users are logged in), bearing in mind that you installed ska correctly, the user logs in after visiting the URL, if it exists (username match) or is otherwise created. There are 3 callbacks that you can configure in the Django settings of your project.
USER_GET_CALLBACK (string): triggered if the user was successfully retrieved from the database (existing user).USER_CREATE_CALLBACK (string): fires immediately after the user is created (the user does not exist).USER_INFO_CALLBACK (string): USER_INFO_CALLBACK when authentication USER_INFO_CALLBACK .
See the documentation ( http://pythonhosted.org/ska/ ) for more information.
Artur Barseghyan Dec 21 '13 at 3:18 2013-12-21 03:18
source share