account acopes
This commit is contained in:
parent
442cf026cb
commit
88d3f53dd8
2 changed files with 9 additions and 4 deletions
|
|
@ -3,7 +3,8 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.views import LoginView
|
from django.contrib.auth.views import LoginView
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope
|
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope, OAuth2Authentication, \
|
||||||
|
TokenMatchesOASRequirements
|
||||||
from rest_framework import generics, permissions, status
|
from rest_framework import generics, permissions, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
|
@ -32,9 +33,13 @@ class UserDetailView(generics.RetrieveAPIView):
|
||||||
|
|
||||||
|
|
||||||
class AccountView(generics.RetrieveUpdateAPIView):
|
class AccountView(generics.RetrieveUpdateAPIView):
|
||||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
|
||||||
serializer_class = AccountSerializer
|
serializer_class = AccountSerializer
|
||||||
required_scopes = []
|
authentication_classes = [OAuth2Authentication]
|
||||||
|
permission_classes = [TokenMatchesOASRequirements]
|
||||||
|
required_alternate_scopes = {
|
||||||
|
"GET": [["accounts.account:retrieve"]],
|
||||||
|
"POST": [["accounts.account:update"]],
|
||||||
|
}
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return self.request.user
|
return self.request.user
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class NotificationClient():
|
||||||
"charset": "utf-8"
|
"charset": "utf-8"
|
||||||
}
|
}
|
||||||
header.setdefault("Authorization", f"Bearer {settings.ACCESS_TOKEN}", )
|
header.setdefault("Authorization", f"Bearer {settings.ACCESS_TOKEN}", )
|
||||||
|
return {}
|
||||||
response = requests.request('post',
|
response = requests.request('post',
|
||||||
f'{settings.NOTIFICATIONS_SERVICE_URL}/notifications/',
|
f'{settings.NOTIFICATIONS_SERVICE_URL}/notifications/',
|
||||||
headers=header,
|
headers=header,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue