Django Google OAuth 2.0にエラー400>Django>情報科学

この記事 > Django > 情報科学
作成 更新

問題:

djangoのsocail loginでGoogle OAuth 2.0にエラー400が表示される。

表示画面:


Google OAuth 2.0 failing with Error 400: invalid_request for some client_id, but works well for others in the same project

Authorization Error
Error 400: invalid_request

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.

You can let the app developer know that this app doesn't comply with one or more Google validation rules.

Request Details
The content in this section has been provided by the app developer. This content has not been reviewed or verified by Google.
If you’re the app developer, make sure that these request details comply with Google policies.

redirect_uri: http://tokyo-teacher.com/accounts/google/login/callback/

原因:


redirect_uri: http://tokyo-teacher.com/accounts/google/login/callback/
のhttp://の部分が問題です。

djangoのsocail loginでは、django側とgoogle側のそれぞれで、設定が必要です。

google側ではAuthorized redirect URIsを設定します。

Authorized redirect URIsは、ユーザーがGoogle OAuth 2.0で認証された後に、django側へリダイレクトされるURIです。(Users will be redirected to this path after they have authenticated with Google)

このリダイレクト先がhttp://となっているので、Google policyに違反していることになり、エラーとなっています。

したがって、
redirect_uri: https://tokyo-teacher.com/accounts/google/login/callback/
のようにhttp://からhttps://に設定変更すると、問題が解決します。

Google OAuth 2.0の設定は google cloud platform > APIs & Services > Credentials できます。

credentialsの設定反映のためには、5分から数時間がかかります。(It may take 5 minutes to a few hours for settings to take effect)

django allauthの流れ:


path('accounts/', include('allauth.urls')),
django側のgoogle social login認証画面の表示
google側の認証
https://tokyo-teacher.com/accounts/google/login/callback/

全文を読む


Django

Github

Python

Nginx

Windows

Linux

PostgreSQL

ウェブ

プログラミング

中学受験講座

高校受験講座

大学受験講座

社会人講座