ios MongoDB Realm Atlas App Services Auth在某些设备上失败

mrfwxfqh  于 2023-08-08  发布在  iOS
关注(0)|答案(1)|浏览(110)

我有一个使用MongoDB Atlas App Services身份验证服务的应用程序,使用Apple作为我的身份验证提供商登录。它工作正常,但在一个设备和所有模拟器上,它会因以下错误而失败。

Error Domain=io.realm.app Code=-1 “[json.exception.parse_error.101]
parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: ‘<’” 
UserInfo={Error Code=-1, Server Log URL=, Error Name=MalformedJson, NSLocalizedDescription=[json.exception.parse_error.101] 
parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: ‘<’}

字符串
当通过登录代码断开时,显然此处发生故障; x1c 0d1x的数据
此时,response.body属性是一个HTML文档,自然无法解析为JSON。

(std::string) body = "<!DOCTYPE html>\n<html>\n  <head>\n      <title>App Services</title>\n      <link rel=\"shortcut icon\" href=\"/static/favicon.ico\" type=\"image/x-icon\" />\n      <style>\n        #app { display: none; }\n      </style>\n      <script>\n        var settings = {\"accountUIBaseUrl\":\"https://account.mongodb.com\",\"adminUrl\":\"https://realm.mongodb.com\",\"apiUrl\":\"https://realm.mongodb.com\",\"bugsnagToken\":\"d93dd442ef3db183db76cc9ded3bc109\",\"chartsUIBaseUrl\":\"https://charts.mongodb.com\",\"cloudUIBaseUrl\":\"https://cloud.mongodb.com\",\"endpointAPIUrl\":\"https://data.mongodb-api.com\",\"endpointAPIUrlsByProviderRegion\":{\"aws-ap-south-1\":\"https://ap-south-1.aws.data.mongodb-api.com\",\"aws-ap-southeast-1\":\"https://ap-southeast-1.aws.data.mongodb-api.com\",\"aws-ap-southeast-2\":\"https://ap-southeast-2.aws.data.mongodb-api.com\",\"aws-eu-central-1\":\"https://eu-central-1.aws.data.mongodb-api.com\",\"aws-eu-west-1\":\"https://eu-west-1.aws.data.mongodb-api.com\",\"aws-eu-west-2\":\"https://eu-west-2.aws.data.mongodb-api.com\",\"aws-sa-east-1\":\"https://sa-east"...


我的登录代码与文档中的描述几乎完全相同,

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        guard
            let credential = authorization.credential as? ASAuthorizationAppleIDCredential,
            let token = credential.identityToken,
            let tokenString = String(data: token, encoding: .utf8)
        else {
            struct NoCredentialsError: Error { }
            presentError(title: "Login Error", error: NoCredentialsError())
            return
        }

        Task { @MainActor in
            do {
                let user = try await realmApp.login(credentials: .apple(idToken: tokenString))
                delegate?.loginViewControllerDidLogin(with: user, name: credential.fullName)
            } catch {
                print(String(describing: error))
                presentError(title: "Login Error", error: error)
            }
        }
    }


tokenString变量已被验证为包含一个看起来真实的标记。
我已经重新安装了Realm,更新到最新版本,清除了swiftpm缓存等。自3月以来,模拟器一直存在此问题。在大多数物理设备和Mac(专为iPad设计)上,它可以按预期工作。
我是不是漏掉了什么奇怪的配置技巧?这是MongoDB端的一个bug吗?

eyh26e7m

eyh26e7m1#

我打乱了整个过程,找到了罪魁祸首。
我在我的RLMApp init中指定了一个baseURL...

let realmApp = App(
    id: "$id",
    configuration: AppConfiguration(
        // baseURL: "https://realm.mongodb.com/groups/#/apps/#",
        localAppName: Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String,
        localAppVersion: Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String
    )
)

字符串
简单地将baseURL注解掉就解决了auth问题,而不会引起其他问题。
Jez.希望这对其他人有用。

相关问题