You can use ska
package, which has password-less login to Django implemented. ska
works with authentication tokens and its security is based on SHARED_KEY which should be equal for all parties (servers) involved.
On client side (party that requests a password-less login), 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': '[email protected]',
'first_name': 'John',
'last_name': 'Doe',
}
)
Default lifetime of the token is 600 seconds. You can customise that by proving a lifetime
argument.
On the server side (site to which users' log in), having in mind that you have installed ska
properly, the user
is logged in upon visiting the URL if they existed (username match), or otherwise - created. There are 3 callbacks that you can customise in your project's Django settings.
USER_GET_CALLBACK
(string): Fired if user was successfully fetched from database (existing user).
USER_CREATE_CALLBACK
(string): Fired right after user has been created (user didn't exist).
USER_INFO_CALLBACK
(string): Fired upon successful authentication.
See the documentation (http://pythonhosted.org/ska/) for more.
force_autenticate
function andAPIClient.force_authenticate
method. – Serin