Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any possible way of single sign on service with django rest framework?

I am trying to develop mobile native apps with ionic2 and django rest framework. And I found django-rest-framework-jwt library that support great jwt authentication. However it doesn't refresh token automatically so that users of mobile apps should type their username and password whenver the token expires..

I already checked another stackoverflow question below. JWT (JSON Web Token) automatic prolongation of expiration

Is there any way that users don't have to type their username and password again? Or Is it ok let token not to be expired and save it local storage of mobile apps so that users don't have to login again?

Thanks in advance!

like image 810
nextdoordoc Avatar asked Jun 22 '16 23:06

nextdoordoc


People also ask

Which authentication is best in Django REST framework?

TokenAuthentication. Note: The token authentication provided by Django REST framework is a fairly simple implementation. For an implementation which allows more than one token per user, has some tighter security implementation details, and supports token expiry, please see the Django REST Knox third party package.

How do you implement OTP based authentication in Django REST framework?

Step 1: Find that phone number existing in the phone model. Step 2: Generate a key of base32 using base64 library. Step 3: Use the Key to generate an Object of class pyotp. Step 4: Now using the Counter of User model and OTP code sent by the user, validate the authenticity of the user.

What is SSO in Django?

django-sso will allow your django application to accept single sign on links from other applications and authenticate users. It is also capable of creating links to other applications that use SSO links. Add sso to your python path, INSTALLED_APPS, and middleware.


1 Answers

I've run into the same scenario with our Django and DRF-based projects, and we wanted to implement Single sign-on using JWT. Since the djangorestframework-jwt library had very little focus on providing SSO capabilities between different projects, I have created a new library for this that properly sets up trust definitions and public/private key pairs.

This library provides two types of JWT tokens:

  1. non-expiring session tokens for your primary login application (aka. "refresh tokens")

  2. short-lived authorization tokens for accessing your other apps (these contain permissions given by the primary app)

The client is expected to first login to your primary login application by POSTing an username and password. The client will receive a permanent session token that will allow subsequent requests to the same server be authenticated. These tokens do not contain any permissions/authorization information and cannot be used for SSO into other apps.

Afterwards, the client is expected to obtain and keep updating authorization tokens using the session token. These secondary tokens are short-lived (15mins..1 hour) and contain the permissions that the user has at the time of issuance. These tokens are used to access other services, which then trust the permissions in the JWT payload for the lifetime of the token.

The current version is v0.0.3 (alpha), but we are moving very fast towards a beta and finally production quality release. The API is already relatively stable and should be final by June 30th 2016. The framework will also have full test coverage in the coming weeks, when we reach the beta stage.

Please check the project page and github for the README.

https://pypi.python.org/pypi/djangorestframework-sso

https://github.com/namespace-ee/django-rest-framework-sso

Please let me know if this would fit your use case, and if it has all the features required. I'll be happy to help with the setup.

like image 160
Lenno Avatar answered Oct 04 '22 00:10

Lenno