-
Notifications
You must be signed in to change notification settings - Fork 286
feat(auth): Link federatedid #345
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
Conversation
ecd0525
to
52608d5
Compare
|
||
UpdateRequest deleteProvider(String providerId) { | ||
checkProviderId(providerId); | ||
properties.put("deleteProvider", ImmutableList.of(providerId)); |
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.
This would overwrite previous values such that:
UpdateRequest ur = ...;
ur.deleteProvider("google.com").deleteProvider("facebook.com")
would result in only the facebook.com provider being deleted.
Better might be: UpdateRequest setDeleteProviders(Iterable<String> providerIds)
. You could optionally add UpdateRequest addDeleteProvider(String)
and/or UpdateRequest addDeleteProviders(Iterable<String>)
.
See further discussion here: http://go/java-practices/builders#special. (Second bullet point).
@@ -528,6 +532,17 @@ UpdateRequest setValidSince(long epochSeconds) { | |||
return this; | |||
} | |||
|
|||
UpdateRequest linkProvider(@NonNull UserProvider userProvider) { |
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.
For our builders (which UpdateRequest effectively is), use setProperty()
rather than property()
. (So setLinkProvider()
here.) Both for consistency with the existing type, (eg setValidSince) and also for consistency with our 'best practices' guide. (http://go/java-practices/builders#api, last bullet point.) Note that this directly conflicts with EJ (as pointed out by the practices doc.)
@@ -528,6 +532,17 @@ UpdateRequest setValidSince(long epochSeconds) { | |||
return this; | |||
} | |||
|
|||
UpdateRequest linkProvider(@NonNull UserProvider userProvider) { |
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.
Note that this part of the api design is currently in flux, so it may change a bit yet. Sorry! :(
No action required (yet).
@@ -528,6 +532,17 @@ UpdateRequest setValidSince(long epochSeconds) { | |||
return this; | |||
} | |||
|
|||
UpdateRequest linkProvider(@NonNull UserProvider userProvider) { |
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.
Should be public (and probably have some javadoc).
return this; | ||
} | ||
|
||
UpdateRequest deleteProvider(String providerId) { |
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.
public/javadoc
assertEquals(1, userRecord.getProviderData().length); | ||
assertTrue(userRecord.getCustomClaims().isEmpty()); | ||
|
||
} finally { |
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.
Good catch.
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.
Other than a few nits, this lgtm. We'll need to wait for the api review before we can make further progress.
any progress on this? This feature would be really great to have. |
Yes: We finally got all the approvals necessary to launch this and have started to do so. The node.js port went out last month (https://firebase.google.com/support/release-notes/admin/node#version_950_-_10_february_2021) and the other ports, incl this one, should be released in the coming weeks. |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
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.
Looks good! Just a couple of nits.
@SuppressWarnings("unchecked") | ||
Iterable<String> deleteProviderIterable = (Iterable<String>)deleteProvider; | ||
|
||
copy.put("deleteProvider", new ImmutableList.Builder<String>() |
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.
Should we handle the double specification case?
user.updateRequest()
.setPhoneNumber(null)
.setProvidersToUnlink(ImmutableList.of("phone"))
I remember handling this case is other languages.
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.
Done. Note that this results in the IllegalArgumentException being wrapped in an ExecutionException, which is a little awkward. (Option 1)
Option 2:
We can resolve that by pulling the property calculation out of the async portion. It's a bit more disruptive, and diverges from how get/posts are handled throughout the rest of the code base. Roughly:
FirebaseUserManager.java:
...
- void updateUser(UserRecord.UpdateRequest request JsonFactory jsonFactory) {
+ void updateUser(Map<String, Object> payload) {
...
(NB: This is not a public interface.)
Option 3:
Alternatively, we could just call request.getProperties()
before the async portion and ignore the results. (i.e. call it twice.)
I've left it as option 1 for now. lmk if you'd prefer 2 or 3.
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.
Would it make sense to enforce this constraint in the setters? We'd have to do so in both setPhoneNumber()
and setProvidersToUnlink()
, but I think we can reduce the duplication via some sort of a helper function. That would make argument validation consistent with the pattern currently used in this class.
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.
Yeah, that's better; done. I've removed the logic here, i.e. if we somehow get into a bad state, we won't notice it. (But now we shouldn't get into that state.)
I didn't create a helper; there wasn't much duplication (though the exception itself is duplicated). If we set the value first and then checked, it would work out better... but that risks leaving the object in a bad state (eg if user catches and ignores the exception and then proceeds to use the object anyways.)
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
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.
LGTM with a suggestion on argument validation.
@SuppressWarnings("unchecked") | ||
Iterable<String> deleteProviderIterable = (Iterable<String>)deleteProvider; | ||
|
||
copy.put("deleteProvider", new ImmutableList.Builder<String>() |
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.
Would it make sense to enforce this constraint in the setters? We'd have to do so in both setPhoneNumber()
and setProvidersToUnlink()
, but I think we can reduce the duplication via some sort of a helper function. That would make argument validation consistent with the pattern currently used in this class.
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
RELEASE NOTE: Add ability to link a federated ID with the
updateUserAsync()
method.