【问题标题】:Is there a way to get a Google OAuth2 token with email and password using Go?有没有办法使用 Go 获取带有电子邮件和密码的 Google OAuth2 令牌?
【发布时间】:2021-12-11 11:37:03
【问题描述】:

我试图避免为我的 Go 应用程序使用服务帐户,并且我需要一种方法来对我的数据库进行身份验证。我找到了authenticate with a service account json 的方法,但我希望找到一种方法,只需要现有 Firebase 用户的电子邮件和密码即可。我将如何在 Go 中执行此操作?

【问题讨论】:

    标签: go firebase-realtime-database oauth-2.0 access-token


    【解决方案1】:

    无法使用提供的 Go Admin SDK 登录 Firebase 身份验证。您可以*做的是将用于 Firebase 身份验证的 REST API 调用到 sign in,然后将其用于实时数据库的 authenticate with the REST API。

    【讨论】:

    • 感谢您的指导。有没有办法使用 firebase 身份验证登录,然后使用该令牌通过 option.WithCredentials() 或其他方式使用管理员 SDK 进行身份验证?
    • 您无法登录 Admin SDK,它以管理权限运行。而且我没有立即看到告诉Go client Admin SDK 包装以传递特定 ID 令牌的方法。
    • From the NewApp function 看起来您可以通过 oauth2.TokenSource 进行身份验证。 “如果客户端选项包含有效的凭据(服务帐户文件、刷新令牌文件或 oauth2.TokenSource),则应用程序将使用该凭据进行身份验证。”这是我可以使用的东西吗?
    • 不,很遗憾没有。 Firebase 身份验证的 ID 令牌是 JWT,据我所知,它无法传递给该调用。
    • Apparently this is what can be passed in 。只是想仔细检查一下这是否是正确的令牌类型。
    猜你喜欢
    • 2014-08-16
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 2019-05-26
    相关资源
    最近更新 更多