Firebase身份验证的Swagger定义

xytpbqjk  于 2022-11-06  发布在  其他
关注(0)|答案(2)|浏览(162)

有没有人能提供一个Swagger安全定义的工作示例?
在后端,使用firebase管理SDK验证firebase ID令牌:

import * as admin from 'firebase-admin';

await admin.auth().verifyIdToken(idToken);

Swagger安全性定义中的值应该是什么,才能为firebase获取正确的ID令牌?

"securityDefinitions": {
        "firebase": {
            "authorizationUrl": "https://accounts.google.com/o/oauth2/v2/auth",
            "flow": "implicit",
            "type": "oauth2",
            "x-google-issuer": "https://securetoken.google.com/MY-PROJECT-ID",
            "x-google-jwks_uri": "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com",
            "x-google-audiences": "MY-CLIENT-ID",
            "scopes": {
                "https://www.googleapis.com/auth/firebase": "Firebase scope"
            }
        }
    }

我确实取回了令牌,但是,firebase admin SDK说它无效:
解码Firebase ID标记失败。请确保传递了表示ID标记的完整字符串JWT
不确定这是因为作用域错误还是标记类型错误...

svmlkihl

svmlkihl1#

使用Firebase对用户进行身份验证/Configuring your OpenAPI document对此进行了说明。
给定的示例肯定没有任何authorizationUrlscopes部分:

securityDefinitions:
  firebase:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    # Replace YOUR-PROJECT-ID with your project ID
    x-google-issuer: "https://securetoken.google.com/YOUR-PROJECT-ID"
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
    x-google-audiences: "YOUR-PROJECT-ID"

此外,还需要将此firebase安全性定义添加到security部分中,无论是在API级别还是在方法级别:

security:
  - firebase: []

读取troubleshooting JWT validation可能会有所帮助。

bsxbgnwa

bsxbgnwa2#

我把这个放在这里只是为了参考
https://github.com/swagger-api/swagger-ui/pull/7699
我已经启动了一个PR,它将启用swagger使用的登录/弹出窗口
使用执行firebase特定逻辑的自定义扩展插件

相关问题