Skip to content

feat(auth): Implement getUserByProviderId - #769

Merged
rsgowman merged 12 commits into
masterfrom
rsgowman/getAccountByProviderId
Feb 8, 2021
Merged

feat(auth): Implement getUserByProviderId#769
rsgowman merged 12 commits into
masterfrom
rsgowman/getAccountByProviderId

Conversation

@rsgowman

@rsgowmanrsgowman commented Jan 20, 2020

Copy link
Copy Markdown
Member

RELEASE NOTE: Added a new getUserByProviderId() to lookup user accounts by their providers.

Comment threadsrc/auth/auth.ts
Comment threadsrc/auth/auth.ts Outdated
* @return A promise fulfilled with the user data corresponding to the
* given provider id.
*/
public getUserByProviderId(providerId: string, providerUid: string): Promise<UserRecord> {

@nrsimnrsimJan 21, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was the final decision to call this method getUserByProviderId or getUserByProviderUid?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Technically neither, since the final decision hasn't been made yet. :)

But you're quite right that the current state uses Uid. Fixed. (Nice catch.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@rsgowman Is it solidated? The released name also conflict with the method name I see here

https://firebase.google.com/support/release-notes/admin/node#9.5.0

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hi @Thaina; the final decision here was to use Uid, i.e. getUserByProviderUid. The release notes are incorrect (caused by my description of this PR not being updated to reflect this change). I'll see if I can get that fixed. Thanks for noticing!

Comment threadtest/integration/auth.spec.ts Outdated
displayName: 'Random User ' + newUserUid,
photoURL: 'http://www.example.com/' + newUserUid + '/photo.png',
disabled: false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove the blank line

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done.

Comment threadtest/integration/auth.spec.ts Outdated
.should.eventually.be.rejected.and.have.property('code', 'auth/user-not-found');
});

it('getUserByProviderId() fails when called with a non-existing federated id', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add unit tests for invalid provider id/uid here as well?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I think they're already covered by the unit tests. Specifically, these ones:
'should be rejected given no federated id'
'should be rejected given an invalid federated id'
'should be rejected given an invalid federated uid'

(Or have I missed something?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant to ask for unit tests in test/unit/auth/auth-api-request.spec.ts.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Oh; I hadn't noticed that. Done.

(More thought required, but I suspect some of those tests may be redundant since we're already effectively testing them from the api level. It might be possible to eliminate some of them.)

@nrsimnrsim assigned rsgowman and unassigned nrsimJan 21, 2020
@rsgowmanrsgowman assigned nrsim and unassigned rsgowmanJan 22, 2020

@nrsimnrsim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM overall.

@nrsimnrsim assigned rsgowman and unassigned nrsimJan 22, 2020

@hiranya911hiranya911 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great. Just a few comments to improve readability.

Comment threadsrc/auth/auth-api-request.ts Outdated
Comment threadsrc/auth/auth.ts Outdated
* @return A promise fulfilled with the user data corresponding to the
* given provider id.
*/
public getUserByProviderUid(providerId: string, providerUid: string): Promise<UserRecord> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here too. Perhaps provider and providerUid?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is what was agreed to in the api review, so I'm reluctant to change that. But if we were to do so:

providerId has prior art (UserINfo, AuthProviderConfig, getProviderConfig, deleteProviderConfig, updateProviderConfig) so I'd prefer to leave that alone.

providerUid however does not. Although a bit overloaded, we could use simply uid here instead. I think it's sufficiently clear.

If we do want to change this, we should also revisit the bulk get PR which uses similar names.

wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel pretty positive about providerId and uid. If we are in agreement, let's go ahead and implement that change. This is a non-breaking change for Node.js (but may be a breaking change for languages like C# that allow named arguments in method calls).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of uid, as it may be confused with Firebase uid (see getUser(uid: string), for example). Having a different name for provider uid would make the distinction explicit.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I'm not 100% sure where this ended up, but at this point, I'm going to go ahead and use Hiranya's suggestion. (But I'm not going to attempt revisiting the bulk get PR.)

However, I haven't changed UserIdentifier.providerUid.

Comment threadtest/integration/auth.spec.ts Outdated
Comment threadtest/unit/auth/auth.spec.ts Outdated

@hiranya911hiranya911 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with the argument rename in the public API pending.

Comment threadtest/integration/auth.spec.ts Outdated
.should.eventually.be.rejected.and.have.property('code', 'auth/user-not-found');
});

it('getUserByProviderUid() fails when called with a non-existing federated id', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/federated/provider/

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done.

@hiranya911hiranya911 removed their assignment Feb 6, 2020
@hiranya911hiranya911 changed the title Implement getUserByProviderIdfeat(auth): Implement getUserByProviderIdFeb 6, 2020

@egilmorezegilmorez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG from the doc perspective with a tiny nit. Thanks!

Comment threadsrc/index.d.ts Outdated
getUserByPhoneNumber(phoneNumber: string): Promise<admin.auth.UserRecord>;

/**
* Gets the user data for the user corresponding to a given provider id.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggest caps like line 1539.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Done.

@google-cla

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@rsgowman@Thaina@hiranya911@egilmorez@nrsim