문제

My django application has two kind of users.

  1. Employer. Uses the default model based authentication backend.
  2. Candidate. Must use the token based authentication backend.

I have the backend in place for employers but how can I use the second token based backend for the candidate related part of the application?

도움이 되었습니까?

해결책

django provides an AUTHENTICATION_BACKENDS setting which should do what you require.

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
)

Ours looks like this ....

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.facebook.FacebookBackend',  # fb backend par social_auth
    'social_auth.backends.twitter.TwitterBackend',  # twitter backend par social_auth
    'backends.EmailAuthBackend',
    'backends.APIAuthBackend',
    'django.contrib.auth.backends.ModelBackend',
)

In out case, the backends.APIAuthBackend is where we check the supplied user auth token. You simply need to write your authentication code in the def authenticate method of that class which returns a user if the token exists.

The django docs provides more info.

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#writing-an-authentication-backend

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top