izaac/jobposting/auth.py
Jakub K 363c60c382
All checks were successful
continuous-integration/drone Build is passing
oauth2 ustawienia + uprawnienia
2024-01-12 17:12:20 +01:00

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