oauth2 ustawienia + uprawnienia
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Jakub K 2024-01-12 17:12:20 +01:00
parent 4fadb033e2
commit 363c60c382
2 changed files with 24 additions and 1 deletions

23
jobposting/auth.py Normal file
View File

@ -0,0 +1,23 @@
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

View File

@ -5,7 +5,7 @@ from core.models import MyUser, AnonymousUserData
from rest_framework import status
from jobposting.permissions import ClientCredentialPermission
from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope, OAuth2Authentication
from jobposting.auth import OAuth2ClientCredentialAuthentication
from .auth import OAuth2ClientCredentialAuthentication
from jobposting.serializers import (