【问题标题】:Firebase admin SDK Python - cannot verify custom tokensFirebase admin SDK Python - 无法验证自定义令牌
【发布时间】:2017-07-05 15:18:26
【问题描述】:

我正在尝试使用 firebase admin sdk for python 来制作自定义令牌并在测试我的应用程序时验证这些令牌。问题是,当我尝试验证令牌时,我总是收到这样的错误:

ValueError: Firebase ID token has incorrect "aud" (audience) claim. Expected "my_project_id" but got "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.

我按照指南创建应用并制作令牌:

import firebase_admin
from firebase_admin import auth, credentials

cred = credentials.Certificate('/path/to/file.json')
app = firebase_admin.initialize(cred)
custom_token = auth.create_custom_token('some-uid', app=app)
auth.verify_id_token(custom_token, app=app)

在这里我得到了错误。似乎 _TokenGenerator 已使用从错误中返回的默认值进行初始化。我认为在传递应用程序时它应该自动更改这些,但它没有发生。我错过了什么吗?

【问题讨论】:

    标签: python firebase firebase-admin


    【解决方案1】:

    verify_id_token() 只接受 ID 令牌。自定义令牌不属于该类别。请参阅此test case。在这种情况下,引发ValueError 是预期的行为。

    ID 令牌可以从client SDK 获得。您可以通过调用提供的 signInWithCustomToken() 方法之一来将自定义令牌换成 ID 令牌。

    【讨论】:

    • 使用自定义令牌登录:firebase.google.com/docs/auth/admin/…
    • 所以signInWithCustomToken() 在 python 中不可用,对吗?它仅在移动开发中可用吗?
    • 对。它在任何 Admin SDK 中均不可用。
    • 会使用 Swift 通过令牌访问桌面上的 firebase 吗?我看到 swift 也可以在 windows 和 aws 上使用,并且令牌登录在 firebase-ios-sdk 中可用。
    猜你喜欢
    • 2018-10-02
    • 2018-12-16
    • 2017-12-19
    • 2019-09-24
    • 1970-01-01
    • 2019-04-09
    • 2023-03-12
    • 2017-07-31
    • 2016-11-06
    相关资源
    最近更新 更多