Ilir
Ilir

Reputation: 450

django oauth toolkit grant client credentials - accounts/login/

I am trying to use oauth for authentication and authorization in a project. I want to use the client credentials grant type as this project is about a middleware/api that will be consumed by a client application. I have created one corresponding client_id and client_secret. The token generation is working, however as soon as I am trying to do a request with the generated token against the api endpoint i am being forwarded to the accounts/login page by django:

                    <td>http://127.0.0.1:8000/accounts/login/?next=/api/mp/</td>

my settings are:

MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'oauth2_provider.middleware.OAuth2TokenMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',]

AUTHENTICATION_BACKENDS = (
'oauth2_provider.backends.OAuth2Backend',)

And this the top of my only function in my views:

@csrf_exempt @require_http_methods(['POST', 'GET']) @login_required() def getUserContext(request):

I am not really understanding where this additional authentication is coming from or resp. how i can tell django to only use oauth for the view.

Upvotes: 1

Views: 1063

Answers (1)

Ilir
Ilir

Reputation: 450

Found the answer very short after posting the questions. However, had been following a howto that stated @login_required to be used. However, the correct decortator to be used is:

@protected_resource()

Upvotes: 1

Related Questions