我正在开发一个 Streamlit 应用程序,它使用 OAuth 2.0 与 Google Sheets 集成进行身份验证。然而,我一次又一次地遇到
Error 400: invalid_request
,指出在尝试进行身份验证时缺少必需的参数 redirect_uri
。
错误截图
我已检查我的 Google Cloud Console 设置和应用程序代码,但未能解决该问题。以下是我的代码和设置的相关部分:
from google_auth_oauthlib.flow import InstalledAppFlow
import streamlit as st
def authenticate_google():
client_config = {
"web": {
"client_id": st.secrets["google_oauth"]["client_id"],
"project_id": st.secrets["google_oauth"]["project_id"],
"auth_uri": st.secrets["google_oauth"]["auth_uri"],
"token_uri": st.secrets["google_oauth"]["token_uri"],
"auth_provider_x509_cert_url": st.secrets["google_oauth"]["auth_provider_x509_cert_url"],
"client_secret": st.secrets["google_oauth"]["client_secret"],
"redirect_uris": st.secrets["google_oauth"]["redirect_uris"],
"javascript_origins": st.secrets["google_oauth"]["javascript_origins"]
}
}
flow = InstalledAppFlow.from_client_config(
client_config,
scopes=['https://www.googleapis.com/auth/spreadsheets.readonly']
)
auth_url, _ = flow.authorization_url(prompt='consent')
return auth_url
-- 我的
secrets.toml
中的 OAuth redirect_uris 配置:
[google_oauth]
redirect_uris = ["http://localhost:8501", "https://your-app-name.streamlitapp.com"]
--
我尝试过但未成功的修复:
我的问题是:
IBM 1944。谷歌 2024。停止 Nimbus 项目。