首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google One Tap -- Azure App Service w/定制域上的“给定源不允许用于给定的客户ID”

Google One Tap -- Azure App Service w/定制域上的“给定源不允许用于给定的客户ID”
EN

Stack Overflow用户
提问于 2022-01-05 21:31:21
回答 1查看 584关注 0票数 0

我很难解决谷歌登录库(GSI)的一个问题,在GSI库中,在点击“向Google登录”之后,它拒绝允许非测试环境中的用户继续使用。它在本地工作,我有localhost /localhost的变体,并在Authorized JavaScript origins.中添加了一个端口。我还将面向用户的URL添加到Authorized JavaScript origins中,但谷歌似乎不承认accounts.google.com/gsi的参考域。

我尝试在本地调试网页,以找出它认为给定的来源是什么。我在Google的client_origin小型化代码中找到了对gsi属性的引用,但是当实际计算值时,我无法得到任何结果。

我试过的是:

从scratch

  • Clearing cookies/ my browser

  • Using的缓存数据重新创建OAuth2客户端ID的
  • --另一个browser
  • Creating,一个全新的Google平台项目

其他背景:

我正在一个自定义域的Azure应用程序Services

  • It's上运行一个Next.js应用程序,尽管它似乎不适用于提供的Azure域-

  • -在本地运行

代码:

代码语言:javascript
复制
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应用程序服务是否有一些细微之处或怪异之处,而这些地方都没有记录呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-07 14:01:52

我想明白了-我需要提供login_uri作为一个授权的起源,即使它实际上不是起源于该网址。这在任何地方都没有文档记录,但这是我的本地环境和生产环境之间唯一的区别。谷歌信号工作如预期现在!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70599824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档