我很难解决谷歌登录库(GSI)的一个问题,在GSI库中,在点击“向Google登录”之后,它拒绝允许非测试环境中的用户继续使用。它在本地工作,我有localhost /localhost的变体,并在Authorized JavaScript origins.中添加了一个端口。我还将面向用户的URL添加到Authorized JavaScript origins中,但谷歌似乎不承认accounts.google.com/gsi的参考域。
我尝试在本地调试网页,以找出它认为给定的来源是什么。我在Google的client_origin小型化代码中找到了对gsi属性的引用,但是当实际计算值时,我无法得到任何结果。
我试过的是:
从scratch
其他背景:
我正在一个自定义域的Azure应用程序Services
代码:
import { Fragment, MutableRefObject, useEffect, useRef } from "react";
import getPublicRuntimeConfig from "lib/utils/get_public_runtime_config";
import Head from "next/head";
import Script from "next/script";
const { publicRuntimeConfig } = getPublicRuntimeConfig();
function handleGsiScriptLoad({
context = "signin",
signonButtonRef
}: {
context?: string;
signonButtonRef: MutableRefObject<HTMLDivElement>;
}) {
google.accounts.id.initialize({
client_id: publicRuntimeConfig.GOOGLE_SSO_CLIENT_ID,
context,
login_uri: publicRuntimeConfig.GAUTH_ENDPOINT,
// Necessary for the cookie to be accessible on the backend (subdomain)
state_cookie_domain: new URL(publicRuntimeConfig.MENTRA_PLATFORM_URL).host,
ux_mode: "redirect"
});
google.accounts.id.renderButton(signonButtonRef.current, {
size: "large",
text: context === "signup" ? "signup_with" : "signin_with",
theme: "outline"
});
}
interface Props {
context?: "signup" | "signin";
}
const GoogleSignon = (props: Props) => {
const signonButtonRef = useRef<HTMLDivElement>();
useEffect(() => {
handleGsiScriptLoad({ context: props.context, signonButtonRef });
}, [props.context]);
return (
<Fragment>
<Head>
{/* Necessary to set the correct origin URL from Azure */}
<meta name="referrer" content="no-referrer-when-downgrade" />
</Head>
<Script
onLoad={handleGsiScriptLoad}
src="https://accounts.google.com/gsi/client"
strategy="beforeInteractive"
/>
<div ref={signonButtonRef} />
</Fragment>
);
};
export default GoogleSignon;我是否错过了阻止Google登录识别我的域名的一些步骤?Azure应用程序服务是否有一些细微之处或怪异之处,而这些地方都没有记录呢?
发布于 2022-01-07 14:01:52
我想明白了-我需要提供login_uri作为一个授权的起源,即使它实际上不是起源于该网址。这在任何地方都没有文档记录,但这是我的本地环境和生产环境之间唯一的区别。谷歌信号工作如预期现在!
https://stackoverflow.com/questions/70599824
复制相似问题