Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Add user property "refreshToken" from FIRUser #123

Open
ti7215fi opened this issue Aug 14, 2021 · 2 comments
Open

iOS: Add user property "refreshToken" from FIRUser #123

ti7215fi opened this issue Aug 14, 2021 · 2 comments

Comments

@ti7215fi
Copy link

Situation/Problem

I have a hybrid Ionic (Capacitor+Cordova) iOS & Android App.
To authenticate the users i uses Firebase Authentication and this cordova plugin. This works really fine (thank you) and there are no problems.

In addition to that, I have one native share extension per platform. Firebase Authentication is also required there to authenticate against my backend.
For Android share extension i can use the Firebase framework directly and can just follow the documentation.
For iOS i can share the idToken from my main app into the extension. This works also fine, but then i can't refresh the idToken if the token is expired. (There are some issues to integrate firebase into a ios extension).

Solution

As a solution i can use the Firebase Authentication REST API: Exchange a refresh token for an ID token. For that i need the refresh_token, but this property is missing in the current implementation. According to the documentation there is this attribute directly in FIRUser. FIRUser#refreshtoken

@chemerisuk I'm not entirely sure, but the following changes should be sufficient, right?

FirebaseAuthenticationPlugin.m

- (CDVPluginResult*)getProfileResult:(FIRUser *)user {
    NSDictionary* result = nil;
    if (user) {
        result = @{
            @"uid": user.uid,
            @"providerId": user.providerID,
            @"displayName": user.displayName ? user.displayName : @"",
            @"email": user.email ? user.email : @"",
            @"phoneNumber": user.phoneNumber ? user.phoneNumber : @"",
            @"photoURL": user.photoURL ? user.photoURL.absoluteString : @"",
            @"emailVerified": [NSNumber numberWithBool:user.emailVerified],
            @"refreshToken": user.refreshToken ? user.refreshToken : @"" // <--- Just add this Line
        };
    }

    return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
}
@chemerisuk
Copy link
Owner

Hey @ti7215fi don't hesitate to create new PR with this change. You also need to add similar property in Android part for consistency.

@ti7215fi
Copy link
Author

Hey @chemerisuk thank you for your answer and your note. 👍
I will check what the equivalent is on Android. getRefreshToken() does not exist there, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants