Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!