iOS Question FireBase Auth Token (SOLVED IT)

walterf25

Expert
Licensed User
Longtime User
Hi All, i have the need to work with firebase database, i came across the FireBase Auth tutorial which allows us to authenticate users using Google or Facebook.

The only thing i don't see is how to get the Token Id, i am using the Rest API for firebase database, i have created a database but it requires me to pass a token id in order for me to be able to insert and read data from the database.

Is there a way to retrieve the token id from the iFireBaseAuth library after the user has been authenticated? If so, how would I be able to do this, i have not been able to find anything in the forums.

I found this code in the documentation in Objective C, but not too sure how to use it using Inline Objective C, can I get some help from the experts, I've tried doing it on my own but get lots of errors.

Retrieve TokenID:
FIRUser *currentUser = [FIRAuth auth].currentUser;
[currentUser getIDTokenForcingRefresh:YES
                           completion:^(NSString *_Nullable idToken,
                                        NSError *_Nullable error) {
          if (error) {
            // Handle error
            return;
          }

          // Send token to your backend via HTTPS
          // ...
}];

Thanks in advance.

Walter
 

walterf25

Expert
Licensed User
Longtime User
Solved it by using the NativeObject library, in case anyone else comes across this and need to also retrieve the TokenID after authenticating with the FireAuth library, here's how i managed to solve it.
Retrieve TokenID:
Private Sub Auth_SignedIn (User As FirebaseUser)
    LogColor("user.displayname: " & User.DisplayName, Colors.Blue)
    Dim no As NativeObject = User
    Dim bl As NativeObject
    Dim nu As NativeObject
    nu = no.RunMethod("auth", Null).RunMethod("currentUser", Null)
    bl = bl.CreateBlock("refreshtoken", 1, False)
    nu.RunMethodWithBlocks("getIDTokenWithCompletion:", Array(bl))
    wait for refreshtoken_Event(args() As Object)
    Dim token As String = args(0)
    Log("token: " & token)
End Sub
 
Upvote 0
Top