23 lines
896 B
Python
23 lines
896 B
Python
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
|
|
from oauth2_provider.models import Application
|
|
from oauth2_provider.oauth2_backends import get_oauthlib_core
|
|
|
|
|
|
class OAuth2ClientCredentialAuthentication(OAuth2Authentication):
|
|
|
|
def authenticate(self, request):
|
|
authentication = super().authenticate(request)
|
|
|
|
if authentication is not None and not self.is_client_credential_request(authentication):
|
|
return authentication
|
|
|
|
if self.is_client_credential_request(authentication):
|
|
access_token = authentication[1]
|
|
user = access_token.application.user
|
|
return user, access_token
|
|
|
|
return None
|
|
|
|
def is_client_credential_request(self, authentication):
|
|
access_token = authentication[1]
|
|
return access_token.application.authorization_grant_type == Application.GRANT_CLIENT_CREDENTIALS |