skip to Main Content

A custom claim luid has been added to the Firebase Authentication from the backend, I’m looking for a way to access this key from the front end for an iOS application.

First I need to check if the key exists and if it exists then get its value.

What have I tried? Everything under Auth.auth().currentUser

Attaching a picture of the decoded JWT data, which shows the key luid

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    This will display a Dictionary with all the keys available for the current user.

     Auth.auth().currentUser?.getIDTokenResult(completion: { (authresult, error) in
         print("CurrentUser Keys", authresult!.claims.keys)
    })
    

    This will return Bool value based on a particular key's availability

    Auth.auth().currentUser?.getIDTokenResult(completion: { (authresult, error) in
         print("CurrentUser Keys", authresult!.claims.keys.contains("luid"))
    })
    

  2. You can check the custom claims this way:

    user.getIDTokenResult(completion: { (result, error) in
      guard let luid = result?.claims?["luid"] as? NSNumber else {
        // luid absent
        return
      }
      //Check for value here and use if-else
    })
    

    Detailed explanation can be found in documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search