1

I have a firebase app. Authentication provider is Auth0, all my users are residing in auth0. I am trying to login with auth0 and than with delegation creating a jwt token to use in firebase. But from firebase I am getting an error.

The error is

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.})

However, the JWT is okay and the id_token is not expired. The payload is

{
  "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"
}

The code segment show, what I am doing after authenticating teh user with email/password and getting the 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)
                    }
            }

This code brings the error above.

Anyone has any idea what is wrong ? Thx in advance...

i-developer
  • 431
  • 4
  • 12

0 Answers0