-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[firebase_auth] Add missing method getIdTokenResult() #1871
Conversation
collinjackson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This is looking good, just a few requests around testing and make sure to reformat so that the bots are happy.
Could you please add unit tests for the added MethodChannel API surface area to test/firebase_auth_test.dart
Could you please also add integration tests to example/test_driver/firebase_auth.dart. Something like this:
test('idTokenResult', () async {
final FirebaseUser user = await auth.signInAnonymously();
String token = await user.getIdToken();
expect(token, isNotNull);
IdTokenResult result = await user.getIdTokenResult();
expect(result.token, token);
// more assertions here
});
| return; | ||
| } | ||
|
|
||
| // Contrary to iOS, android has a single method to handle getIdToken() and getIdTokenResult() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Contrary to iOS, android has a single method to handle getIdToken() and getIdTokenResult() | |
| // Contrary to iOS, Android has a single method to handle `getIdToken()` and `getIdTokenResult()` |
|
After looking at this more carefully, I think that |
|
I understand, in my opinion there should be only but 1 method. Javascript and iOS Firebase SDKs provide 2 methods, while Android SDK provides only 1. What about deprecating |
|
Haven't forgotten about this one, I should have a naming decision soon and then we can move forward. Thanks for your patience. |
|
No problem. I'll wait on your decision before implementing the tests. |
collinjackson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feedback that I got from naming committee was to change the signature of getIdToken to Future<IdTokenResult> getIdToken({bool refresh = false});. And at the same time make a breaking change to sign-in methods so that they return an AuthResult instead of a FirebaseUser. We are choosing to diverge from the React Native / web SDK's UserCredential naming and two getIdToken* methods that are there for historical reasons.
|
Implemented changes for renaming, updated the tests and the changelog. |
Update comments
|
I think we should call it This lines up with what's happening in #1919 where I want to change |
|
Makes sense. Let me know if there is anything else I can do. |
|
@collinjackson lol, I was just looking for this and couldn't find it in 0.11! I guess I'll have to try your new version asap. =) |
* Implement IdResultToken type and update getIdTokenResult * Add tests
* Implement IdResultToken type and update getIdTokenResult * Add tests
Description
Firebase auth is missing the method
getIdTokenResult()which is available on native SDKs. It allows to retrieve the current token + other useful info like the token custom claims.The PR includes the changes:
Future<IdTokenResult> getIdTokenResult(bool refresh)IdTokenResultgetIdTokenResult(BOOL refresh)getIdTokenon Android, in order to handle bothgetIdToken()andgetIdTokenResult(). The reason is the firebase Android SDK only provides one methodgetIdToken, which returns the id token result. The method now returns only the token or the whole token result, depending on the dart call.What is missing: tests, changelog, version bump.
Will add these later.
Related Issues
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?