gpt4 book ai didi

ios - iOS 上的 Firebase AppCheck : 403 permission errors - PERMISSION_DENIED

转载 作者:行者123 更新时间:2023-12-04 14:04:17 51 4
gpt4 key购买 nike

问:
如何解决 Firebase App Check 的权限错误?
背景:
我已根据文档启用 App Check:
DeviceCheck 已启用/配置为:
https://firebase.google.com/docs/app-check/ios/devicecheck-provider
App Attest 已启用,配置如下:
https://firebase.google.com/docs/app-check/ios/devicecheck-provider
SDK 被添加到项目中,代码来自:
https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseAppCheck/Apps/FIRAppCheckTestApp/FIRAppCheckTestApp/AppDelegate.swift
具体来说,在 appdelegate 中:
token 设置:

FirebaseApp.configure()

requestDeviceCheckToken()

requestDebugToken()

if #available(iOS 14.0, *) {
requestAppAttestToken()
}
调用:
  // MARK: App Check providers
func requestDeviceCheckToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

DeviceCheckProvider(app: firebaseApp)?.getToken { token, error in
if let token = token {
print("DeviceCheck token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("DeviceCheck error: \((error as NSError).userInfo)")
}
}
}

func requestDebugToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

if let debugProvider = AppCheckDebugProvider(app: firebaseApp) {
print("Debug token: \(debugProvider.currentDebugToken())")

debugProvider.getToken { token, error in
if let token = token {
print("Debug FAC token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("Debug error: \(error)")
}
}
}
}

@available(iOS 14.0, *)
func requestAppAttestToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

guard let appAttestProvider = AppAttestProvider(app: firebaseApp) else {
print("Failed to instantiate AppAttestProvider")
return
}

appAttestProvider.getToken { token, error in
if let token = token {
print("App Attest FAC token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("App Attest error: \(error)")
}
}
}
requestDeviceCheckToken() 返回权限错误:
DeviceCheck error: ["NSLocalizedFailureReason": The server responded with an error: 
- URL: https://firebaseappcheck.googleapis.com/v1beta/projects/<GOOGLE_APP_ID>:exchangeDeviceCheckToken
- HTTP status code: 403
- Response body: {
"error": {
"code": 403,
"message": "Requests from this iOS client application \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_IOS_APP_BLOCKED",
"domain": "googleapis.com",
"metadata": {
"service": "firebaseappcheck.googleapis.com",
"consumer": "projects/<my project #>"
}
}
]
}
}
requestDebugToken() 返回权限错误:
Debug error: Error Domain=com.firebase.appCheck Code=0 "The server responded with an error: 
- URL: https://firebaseappcheck.googleapis.com/v1beta/projects/<GOOGLE_APP_ID>:exchangeDebugToken
- HTTP status code: 403
- Response body: {
"error": {
"code": 403,
"message": "Requests from this iOS client application \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_IOS_APP_BLOCKED",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects/<my project #>",
"service": "firebaseappcheck.googleapis.com"
}
}
]
}
}
" UserInfo={NSLocalizedFailureReason=The server responded with an error:
- URL: https://firebaseappcheck.googleapis.com/v1beta/projects/<GOOGLE_APP_ID>:exchangeDebugToken
- HTTP status code: 403
- Response body: {
"error": {
"code": 403,
"message": "Requests from this iOS client application \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_IOS_APP_BLOCKED",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects/<my project #",
"service": "firebaseappcheck.googleapis.com"
}
}
]
}
}
}
requestAppAttestToken() 返回错误:
App Attest error: Error Domain=com.firebase.appCheck Code=0 "(null)"
GCP Console 确实显示了对以下 100% 错误的所有调用:
google.firebase.appcheck.v1beta.TokenExchangeService.ExchangeDebugToken 
google.firebase.appcheck.v1beta.TokenExchangeService.ExchangeDeviceCheckToken
google.firebase.appcheck.v1beta.TokenExchangeService.GenerateAppAttestChallenge
所有这些似乎都指向权限错误?具体来说,GOOGLE_APP_ID 在请求 URL 中,但 App Check 是通过控制台在 Firebase 中配置的...
我在文档中没有看到任何内容,也没有在 IAM 中看到任何我遗漏的明显内容? :(
提前寻求帮助!
更新
在与 Postman 进一步测试后:
问题似乎是 SDK 没有通过 X-Ios-Bundle-Identifier正确调用 AppCheck API 时。
得出这个结论的步骤:
  • 来自 postman :带有原始 API_KEY 的 API 调用 -> 产生初始(以上)错误响应/403
  • 来自 POSTMAN:API 调用如上所述,+ X-Ios-Bundle-Identifier + 有效 debug_token -> 产生成功负载。

  • 所以:
  • 任何想法来帮助识别为什么 X-Ios-Bundle-Identifier没有被 SDK 传递?该应用程序正在使用其他 Firebase API 的无问题,因此似乎仅限于 AppCheck SDK...
  • 和/或 - 可以 X-Ios-Bundle-Identifier以编程方式(在 Swift 中)添加到 AppCheck 调用(在 .plist 中正确标记)

  • 解决!
    App Check SDK 目前不支持 API key 的 Android/iOS 应用程序限制。因此,您必须删除 API key 的应用限制才能解决此问题。
    希望在某个时候支持应用程序限制...
    更新!
    v8.8.0-beta 现在支持包 ID! :)

    最佳答案

    App Check SDK 目前不支持 API key 的 Android/iOS 应用程序限制。因此,您必须删除 API key 的应用限制才能解决此问题。
    希望在某个时候支持应用程序限制...

    关于ios - iOS 上的 Firebase AppCheck : 403 permission errors - PERMISSION_DENIED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69034953/

    51 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com