oauth2 ustawienia + uprawnienia
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
4fadb033e2
commit
363c60c382
23
jobposting/auth.py
Normal file
23
jobposting/auth.py
Normal 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
|
||||
@ -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 (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user