1

I am integrating Firebase Authentication with MongoDB Stitch Custom Authentication on Swift iOS and would like to pass user's information from firebase to mongodb so that user's email or name can displayed on MongoDB's console here:

enter image description here

Base on MongoDB's docs, these can be accessed via the metadata from the JWT, but I do not know how to add them from iOS. This is how I authenticate from Firebase to Stitch:

Auth.auth().signIn(with: credential) { (results, error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }

        if let results = results {
            results.user.getIDTokenForcingRefresh(true) { (tokenId, error) in
                if let error = error {
                    completion(error)
                }

                if let tokenId = tokenId {
                    let credential = CustomCredential.init(withToken: tokenId)
                    stitch.auth.login(withCredential: credential) { (result) in
                        switch result {
                        case .success(let user):
                            print("Sign in to Stitch successful")
                        case .failure(let e):
                            print(e)
                        }
                    }
                }
            }
        }
    }
}

The above authentication method works and I can authenticate successfully on Stitch. But how can I extract the Provider Data from Firebase and display them on MongoDB?

Koh
  • 2,687
  • 1
  • 22
  • 62

1 Answers1

0

You have to configure your provider under Users > Providers > Custom JWT Authentication then Map the fields accordingly.

this image

enter image description here

will map the fields like this:

enter image description here

Orville
  • 518
  • 7
  • 17