Skip to content

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

Merged
merged 7 commits into from
Apr 20, 2021
Merged

feat(auth): Link federatedid #345

merged 7 commits into from
Apr 20, 2021

Conversation

nrsim
Copy link
Contributor

@nrsim nrsim commented Jan 9, 2020

RELEASE NOTE: Add ability to link a federated ID with the updateUserAsync() method.

@nrsim nrsim requested a review from rsgowman January 9, 2020 19:36
@nrsim nrsim force-pushed the link-federatedid branch from ecd0525 to 52608d5 Compare January 9, 2020 19:46

UpdateRequest deleteProvider(String providerId) {
checkProviderId(providerId);
properties.put("deleteProvider", ImmutableList.of(providerId));
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Member

@rsgowman rsgowman left a 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.

@Michael-Frank
Copy link

any progress on this? This feature would be really great to have.

@rsgowman
Copy link
Member

rsgowman commented Mar 2, 2021

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.

@google-cla
Copy link

google-cla bot commented Mar 17, 2021

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 @googlebot I consent. in this pull request.

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 cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@rsgowman rsgowman requested a review from hiranya911 March 17, 2021 21:27
@rsgowman rsgowman assigned hiranya911 and unassigned nrsim Mar 17, 2021
Copy link
Contributor

@hiranya911 hiranya911 left a 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>()
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.)

@hiranya911 hiranya911 assigned rsgowman and unassigned hiranya911 Mar 19, 2021
@google-cla
Copy link

google-cla bot commented Mar 31, 2021

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 @googlebot I consent. in this pull request.

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 cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@rsgowman rsgowman assigned hiranya911 and unassigned rsgowman Mar 31, 2021
Copy link
Contributor

@hiranya911 hiranya911 left a 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>()
Copy link
Contributor

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.

@hiranya911 hiranya911 assigned rsgowman and unassigned hiranya911 Apr 1, 2021
@google-cla
Copy link

google-cla bot commented Apr 9, 2021

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 @googlebot I consent. in this pull request.

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 cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@rsgowman rsgowman assigned hiranya911 and unassigned rsgowman Apr 9, 2021
@hiranya911 hiranya911 assigned rsgowman and unassigned hiranya911 Apr 19, 2021
@hiranya911 hiranya911 changed the title Link federatedid feat(auth): Link federatedid Apr 20, 2021
@hiranya911 hiranya911 merged commit 40c25e8 into master Apr 20, 2021
@hiranya911 hiranya911 deleted the link-federatedid branch April 20, 2021 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants