【发布时间】:2019-10-22 12:22:59
【问题描述】:
使用 Django Rest 框架,当我想生成令牌时,我尝试添加一个自定义字段(氏族),它应该是必填字段和现有氏族。
喜欢:
curl -X POST -d "grant_type=password&username=username&password=password&client_id=client_id&client_secret=client_secret&clan=ABCDEF" http://localhost:8000/o/token/
我的用户模型:
class User(AbstractUser):
"""
User model.
"""
clans = models.ManyToManyField(Clan, related_name='Users')
我的休息框架设置:
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'apps.core.api.pagination.StandardPagination',
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
),
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'EXCEPTION_HANDLER': 'apps.core.exceptions.api.custom_exception_handler',
}
那我想要一个经典的回应:
{
"access_token": "azerty123456789",
"expires_in": 36000,
"token_type": "Bearer",
"scope": "read write groups",
"refresh_token": "azerty123456789"
}
【问题讨论】:
标签: oauth-2.0 django-rest-framework