| 1 |
from rest_framework.response import Response |
| 2 |
from rest_framework.views import APIView |
| 3 |
|
| 4 |
from allauth.idp.oidc.contrib.rest_framework.authentication import TokenAuthentication |
| 5 |
from allauth.idp.oidc.contrib.rest_framework.permissions import TokenPermission |
| 6 |
|
| 7 |
|
| 8 |
class ResourceView(APIView): |
| 9 |
authentication_classes = [TokenAuthentication] |
| 10 |
permission_classes = [TokenPermission.has_scope(["view-resource"])] |
| 11 |
|
| 12 |
def get(self, request, *args, **kwargs): |
| 13 |
return Response( |
| 14 |
{ |
| 15 |
"resource": "ok", |
| 16 |
"user_email": ( |
| 17 |
request.user.email |
| 18 |
if request.user and request.user.is_authenticated |
| 19 |
else None |
| 20 |
), |
| 21 |
} |
| 22 |
) |