获得 “token”: [ “确保此字段不超过500个字符。” ] 在 drf social oauth2

huangapple go评论91阅读模式
英文:

Got "token": [ "Ensure this field has no more than 500 characters." ] in drf social oauth2

问题

Here is the translated code:

  1. REST_FRAMEWORK = {
  2. 'DEFAULT_AUTHENTICATION_CLASSES': (
  3. 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
  4. 'drf_social_oauth2.authentication.SocialAuthentication',
  5. ),
  6. }
  7. AUTHENTICATION_BACKENDS = (
  8. 'social_core.backends.google.GoogleOAuth2',
  9. # drf-social-oauth2
  10. 'drf_social_oauth2.backends.DjangoOAuth2',
  11. # Django
  12. 'django.contrib.auth.backends.ModelBackend',
  13. )
  14. SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'my key'
  15. SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'my secrect'
  16. # Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.
  17. # Email is not sent by default, to get it, you must request the email permission.
  18. SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
  19. 'https://www.googleapis.com/auth/userinfo.email',
  20. 'https://www.googleapis.com/auth/userinfo.profile',
  21. ]

If you have any other code or text to translate, please provide it, and I'll be happy to assist further.

英文:
  1. REST_FRAMEWORK = {
  2. 'DEFAULT_AUTHENTICATION_CLASSES': (
  3. 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
  4. 'drf_social_oauth2.authentication.SocialAuthentication',
  5. ),
  6. }
  7. AUTHENTICATION_BACKENDS = (
  8. 'social_core.backends.google.GoogleOAuth2',
  9. # drf-social-oauth2
  10. 'drf_social_oauth2.backends.DjangoOAuth2',
  11. # Django
  12. 'django.contrib.auth.backends.ModelBackend',
  13. )
  14. SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'my key'
  15. SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'my secrect'
  16. # Define SOCIAL_AUTH_FACEBOOK_SCOPE to get extra permissions from Facebook.
  17. # Email is not sent by default, to get it, you must request the email permission.
  18. SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
  19. 'https://www.googleapis.com/auth/userinfo.email',
  20. 'https://www.googleapis.com/auth/userinfo.profile',
  21. ]

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

huangapple
  • 本文由 发表于 2023年5月26日 14:42:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338245.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定