我正在使用 django-rest-auth
通过 API 进行社交身份验证。
我已经配置了 Facebook,它运行良好,但我在使用 Google 社交身份验证时遇到了一些问题。
- 我已经添加到
INSTALLED_APPS
:
allauth.socialaccount.providers.google',
- 创建的 View :
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
class CustomGoogleOAuth2Adapter(GoogleOAuth2Adapter):
basic_auth = False
class GoogleLogin(SocialLoginView):
adapter_class = CustomGoogleOAuth2Adapter
client_class = OAuth2Client
- 由管理面板创建应用
- 我从 https://developers.google.com/oauthplayground/ 得到了
access_token
- 当我尝试通过端点登录时出现错误:
Reverse for 'redirect' not found. 'redirect' is not a valid view function or pattern name.
最佳答案
很难查明错误,因为您没有包含其余代码。该错误仅表示它找不到名称为“redirect”的 url。因此,您可以检查两件事:
- 您是否按照 django-rest-auth document 为端点设置了正确的 url 设置? ?
urlpatterns = [
...,
url(r'^rest-auth/', include('rest_auth.urls'))
]
- 或者,根据 django-all-auth document,您可能在指定 Google 社交应用程序时忘记了重定向 URL ?
Under “APIs & auth” go to “Credentials” and create a new Client ID. Probably you will want a “Web application” Client ID. Provide your domain name or test domain name in “Authorized JavaScript origins”. Finally fill in http://127.0.0.1:8000/accounts/google/login/callback/ in the “Authorized redirect URI” field. You can fill multiple URLs, one for each test domain. After creating the Client ID you will find all details for the Django configuration on this page.
关于django-rest-auth 通过访问 token 进行谷歌社交身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54479789/