我正在使用 django oauth2 工具包。任何人都可以帮助我理解吗?
- 我能够根据扩展的 AbstractUser 模型注册用户。
- 根据注册详细信息,我可以通过输入用户名、密码、client_id、client_secret 和 grant_type 对用户进行身份验证。
- 在这些中输入登录凭据、ID 和密码后
(127.0.0.1:8000/o/token/)
,我可以获得访问和刷新令牌 - 获取 access_token 时,如何将用户详细信息与 access_token 一起传递。谁能帮我整理一下这些。我正在使用邮递员。
序列化程序.py
from rest_framework import serializers
from django.contrib.auth import authenticate
from rest_framework.response import Response
from django.contrib.auth import get_user_model
User = get_user_model()
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('first_name','last_name','username','password','email','date_of_birth',
'profile_image','bio','role','gender')
extra_kwargs = {'is_staff': {'write_only':True},
'is_active':{'write_only':True},
'password':{'write_only':True}}
def create(self, validated_data):
return User.objects.create_user(**validated_data)
视图.py
from django.shortcuts import render
from rest_framework import generics, permissions, serializers, viewsets
from rest_framework.response import Response
from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope, TokenHasScope
from users.serializers import UserSerializer
from users.models import User
# Create your views here.
class UserAPI(viewsets.ModelViewSet):
serializer_class = UserSerializer
queryset = User.objects.all()
网址.py
from django.urls import path, include
from rest_framework import routers
from rest_framework.routers import DefaultRouter
from users.views import UserAPI
from users import views
router = DefaultRouter()
router.register('users', views.UserAPI, basename='users')
urlpatterns = router.urls