2

我有一个 Firebase 应用程序。身份验证提供程序是 Auth0,我所有的用户都居住在 auth0 中。我正在尝试使用 auth0 登录,而不是使用委托创建 jwt 令牌以在 firebase 中使用。但是从firebase我得到一个错误。

错误是

Login Error happened: Optional(Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x618000252ed0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
    code = 400;
    errors =     (
                {
            domain = usageLimits;
            message = "Bad Request";
            reason = keyExpired;
        }
    );
    message = "Bad Request"; }}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.})

但是,JWT 没问题,id_token 没有过期。有效载荷是

{
  "uid": "auth0|58f1d133c6623f69e82eaccd",
  "iat": 1492376288,
  "exp": 1492379888,
  "aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
  "iss": "firebase-adminsdk-b69t9@mein-dienstplan-6cd8e.iam.gserviceaccount.com",
  "sub": "firebase-adminsdk-b69t9@mein-dienstplan-6cd8e.iam.gserviceaccount.com"
}

代码段显示,在使用电子邮件/密码验证用户并获取 id_token 后我在做什么,

            Auth0
                .authentication()
                .delegation(withParameters: ["id_token": self.id_token!,
                                             "target_client": "116821977303633943003",
                                             "grant_type" : "urn:ietf:params:oauth:grant-type:jwt-bearer",
                                             "scope": "openid profile",
                                             "api_type": "firebase"])
                .start { result in
                    switch(result) {
                    case .success(let credentials):
                        if let idToken = credentials["id_token"] as? String {
                            print("FIREBASE TOKEN = \(idToken)")

                            FIRAuth.auth()?.signIn(withCustomToken: idToken) { (user, error) in

                                guard let user = user else {
                                    callback(error)
                                    return
                                }
                                print("Firebase user \(user)")
                                callback(nil)
                            }

                            callback(nil)
                        } else {
                            callback(UserSessionError.noIdToken)
                        }
                    case .failure(let error):
                        callback(error)
                    }
            }

这段代码带来了上面的错误。

有人知道出了什么问题吗?提前谢谢...

4

0 回答 0