Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

386
Vistas
Using Firebase Auth, want to use JWT to Auth clients (iOS App) sending MongoDB requests

I am currently using Firebase Auth to authenticate all users and using mongodb realm/ realm sync/ atlas as my DB. From what I have heard, using 2 separate 'auths' (firebase and mongo) and linking them with the Firebase UID as a key seems like a bad idea. As such, JWT's seem like my best bet.

I feel as the following code is a-ok, but the config on the realm app is iffy: I keep getting that the public key is not PEM formatted when I use custom JWT token and when I use the JWK URI (https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com) I get the following error:

Login failed: failed to fetch JWK from URI: failed to construct key from keys: unsupported kty type Error Domain=realm::app::ServiceError Code=47 "failed to fetch JWK from URI: failed to construct key from keys: unsupported kty type " UserInfo={NSLocalizedDescription=failed to fetch JWK from URI: failed to construct key from keys: unsupported kty type , realm::app::ServiceError=AuthError}

// Function is supposed to auth user using mongo auth by using the firebase jwt
func authJWTMongo(completion: @escaping (Bool) -> Void) -> Void{
        let currentUser = Auth.auth().currentUser
        currentUser?.getIDTokenForcingRefresh(true) { idToken, error in
            if error != nil {
                print("Totally f'ed the mongoAuth")
                completion(false)
                return;
            }

            // Auth using Mongo shit
            print("JWT is< \(String(describing: idToken))>")
            if let idToken = idToken{
                let credentials = Credentials.jwt(token: idToken)
                app.login(credentials: credentials) { (result) in
                    switch result {
                    case .failure(let error):
                        print("Login failed: \(error.localizedDescription)")
                        print("\(error)")
                        completion(false)
                    case .success(let user):
                        print("Successfully logged in as user \(user)")
                        completion(true)
                        // Now logged in, do something with user
                        // Remember to dispatch to main if you are doing anything on the UI thread
                    }
                }
            }
        }
    }

Any help is appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Apparently the correct JWK URI is https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com

Nothing wrong with the swift code above.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda