Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

customize djangorestframework-jwt for authentication with email or username interchangeably and password #84

Closed
xmonfort opened this issue Mar 5, 2015 · 3 comments

Comments

@xmonfort
Copy link

xmonfort commented Mar 5, 2015

I am writing a backend api using django rest-framework. I would like jwt authentication using email or username interchangeably (one or other) and password instead of using username and password.
Is there any way using your djangorestframework-jwt package?

Thanks in advance.

Xavier Monfort Faure

@jpadilla
Copy link
Owner

jpadilla commented Mar 6, 2015

@xmonfort There are a couple of ways, you could write your own serializer based off JSONWebTokenSerializer. It currently uses your User's model USERNAME_FIELD, which by default is username. It uses your authentication backend to authenticate your user based on that field and password. You could use the default serializer implementation and probably just have a a custom authentication backend that checks if the username looks like an email and try to find a user that way.

@jpadilla jpadilla closed this as completed Mar 6, 2015
@titusjoyson
Copy link

I need to add an additional field in JSONWebTokenSerializer so i can use it in authenticate() function, but i don't know how to extend and implement it, is there any reference to do it.

@elflamo
Copy link

elflamo commented Sep 13, 2017

https://stackoverflow.com/questions/34332074/django-rest-jwt-login-using-username-or-email/46191939#46191939

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants