英文:
Got "token": [ "Ensure this field has no more than 500 characters." ] in drf social oauth2
问题
Here is the translated code:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
'drf_social_oauth2.authentication.SocialAuthentication',
),
}
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
# drf-social-oauth2
'drf_social_oauth2.backends.DjangoOAuth2',
# Django
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'my key'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'my secrect'
# Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.
# Email is not sent by default, to get it, you must request the email permission.
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
]
If you have any other code or text to translate, please provide it, and I'll be happy to assist further.
英文:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
'drf_social_oauth2.authentication.SocialAuthentication',
),
}
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
# drf-social-oauth2
'drf_social_oauth2.backends.DjangoOAuth2',
# Django
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'my key'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'my secrect'
# Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.
# Email is not sent by default, to get it, you must request the email permission.
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
]
I am using drf-social-oauth2 for Google login. After getting a Google credential from React site. i tried to use 'curl -X POST -d "grant_type=convert_token&client_id=<django-oauth-generated-client_id>&client_secret=<django-oauth-generated-client_secret>&backend=google-oauth2&token=<google_token>" http://localhost:8000/auth/convert-token'
But I got "token": ["Ensure this field has no more than 500 characters."]
答案1
得分: 1
你可以尝试使用版本1.3.0或2.0.0。
我正在使用Microsoft Graph作为后端,在版本大于2.0.0中遇到了相同的问题。
英文:
You can try with version 1.3.0 or 2.0.0
I'm using microsoft graph as backend and encountered same issue too in version > 2.0.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论