Oz Bar-Shalom
Oz Bar-Shalom

Reputation: 1855

Django rest - Custom authentication backend with browsable api

I am using Django 1.11 and Django rest framework 3.6.2 I created a custom authentication backend:

MyAuthBackend(rest_framework.authentication.BasicAuthentication): 
    # ...

and added it to the settings.py file:

REST_FRAMEWORK = {  
    'DEFAULT_AUTHENTICATION_CLASSES' : ('path.to.MyAuthBackend',)

}

I also tried to extend SessionAuthentication without success

My issue is that users are trying to log in via the browsable api and it looks like the authentication backend that the browsable api is using is not the default one.

Where can I change that? I have to use my own auth backend in the browsable api, Thank you.

Upvotes: 2

Views: 654

Answers (1)

Igonato
Igonato

Reputation: 10777

I don't think it's possible to use BasicAuthentication in the browseable api (without changing a whole bunch of its internals).

Consider keeping the SessionAuthentication alongside your new one, you can use basic authentication in your app and session authentication in the browsable api:

'DEFAULT_AUTHENTICATION_CLASSES': (
    'path.to.MyAuthBackend',
    'rest_framework.authentication.SessionAuthentication',
),

Upvotes: 1

Related Questions