本地测试Google登录遇到oAuth同意屏幕授权域名的问题。
创始人
2024-11-29 05:01:32
0

在 Google Cloud Platform 控制台中将同意屏幕授权域添加为本地测试域。具体步骤如下:

  1. 登录 Google Cloud Platform 控制台,进入对应的项目。
  2. 选择“API 与服务” -> “凭据” -> 选择相应的客户端 ID。
  3. 在“授权的 JavaScript 来源”和“授权的重定向 URI”中添加本地测试的 URL。
  4. 在代码中使用授权的客户端 ID 和 secret 进行 Google 登录。

示例代码:

from google.oauth2 import id_token
from google.auth.transport import requests

# The CLIENT_ID and CLIENT_SECRET in the following code come from
# the API Console Credentials page:
#   https://console.developers.google.com/apis/credentials
CLIENT_ID = ''
CLIENT_SECRET = ''

# Use the following redirect URI when running the sample on your
# development server. After deploying your application to production,
# use your own URL.
REDIRECT_URI = 'http://localhost:8080/oauth'

# ...
auth_request = request('https://accounts.google.com/o/oauth2/auth', ...)
auth_response_text = auth_response.text
if 'accounts.google.com/o/oauth2/approval' in auth_response_text:
    # Send an empty POST request to the approval URL:
    approval_response = requests.post(auth_response.url, data={}, ...)
    # ...
# ...
if self.request.get('code'):
    # Exchange the authorization code for a refresh token and access token:
    authorization_code = self.request.get('code')
    credentials = flow.step2_exchange(authorization_code)
    userid = credentials.id_token['sub']
    # ...

其中,需要替换为自己的客户端 ID 和 secret。= 'http://localhost:8080/oauth' 需要替换为自己的本地测试 URL。

相关内容

热门资讯

安卓换鸿蒙系统会卡吗,体验流畅... 最近手机圈可是热闹非凡呢!不少安卓用户都在议论纷纷,说鸿蒙系统要来啦!那么,安卓手机换上鸿蒙系统后,...
安卓系统拦截短信在哪,安卓系统... 你是不是也遇到了这种情况:手机里突然冒出了很多垃圾短信,烦不胜烦?别急,今天就来教你怎么在安卓系统里...
app安卓系统登录不了,解锁登... 最近是不是你也遇到了这样的烦恼:手机里那个心爱的APP,突然就登录不上了?别急,让我来帮你一步步排查...
安卓系统要维护多久,安卓系统维... 你有没有想过,你的安卓手机里那个陪伴你度过了无数日夜的安卓系统,它究竟要陪伴你多久呢?这个问题,估计...
安卓系统如何卸载app,轻松掌... 手机里的App越来越多,是不是感觉内存不够用了?别急,今天就来教你怎么轻松卸载安卓系统里的App,让...
windows官网系统多少钱 Windows官网系统价格一览:了解正版Windows的购买成本Windows 11官方价格解析微软...
怎么复制照片安卓系统,操作步骤... 亲爱的手机控们,是不是有时候想把自己的手机照片分享给朋友,或者备份到电脑上呢?别急,今天就来教你怎么...
安装了Anaconda之后找不... 在安装Anaconda后,如果找不到Jupyter Notebook,可以尝试以下解决方法:检查环境...
安卓系统应用怎么重装,安卓应用... 手机里的安卓应用突然罢工了,是不是让你头疼不已?别急,今天就来手把手教你如何重装安卓系统应用,让你的...
iwatch怎么连接安卓系统,... 你有没有想过,那款时尚又实用的iWatch,竟然只能和iPhone好上好?别急,今天就来给你揭秘,怎...