Skip to content

feat(auth): Add support for Auth Emulator - #1044

Merged
yuchenshi merged 15 commits into
masterfrom
ss-auth-emulator-support
Oct 16, 2020
Merged

feat(auth): Add support for Auth Emulator#1044
yuchenshi merged 15 commits into
masterfrom
ss-auth-emulator-support

Conversation

@samtstern

@samtstern samtstern commented Sep 28, 2020

Copy link
Copy Markdown
Contributor

Discussion

For Googlers: this design doc explains the behavior changes and security implications.

  • Basic URL replacement
  • Short-circuit custom auth token signing
  • Short-circuit verifyIdToken

Testing

  • New unit tests

API Changes

N/A

RELEASE NOTE: Added support for Firebase Auth Emulator.

@samtstern samtstern changed the title WIP: Add support for Auth Emulator Add support for Auth Emulator Sep 29, 2020
Comment thread src/auth/token-verifier.ts Outdated
Comment thread test/resources/mocks.ts Outdated
@yuchenshi

Copy link
Copy Markdown
Member

BTW awesome work, will take a detailed pass later once we settle the bigger picture questions

@yuchenshi yuchenshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM (pending verifyIdToken change)

Comment thread src/auth/token-verifier.ts Outdated
Comment thread test/resources/mocks.ts Outdated
Comment thread test/unit/auth/token-verifier.spec.ts Outdated

@hiranya911 hiranya911 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 mostly good. I've made some suggestions on cleaning up the implementation and improving the test coverage.

Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/auth.ts Outdated
Comment thread src/auth/auth-api-request.ts
Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/token-verifier.ts Outdated
private readonly shortNameArticle: string;

constructor(private clientCertUrl: string, private algorithm: string,
constructor(private clientCertUrl: string, private algorithm: jwt.Algorithm,

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.

This really ought to accept an options object. But it's ok to do that later.

Comment thread src/auth/token-generator.ts Outdated
Comment thread test/unit/auth/token-generator.spec.ts
Comment thread test/unit/auth/token-verifier.spec.ts Outdated
* @inheritDoc
*/
public getAccountId(): Promise<string> {
return Promise.resolve('firebase-auth-emulator@example.com');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not so sure about this ... could we do something better here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably the best thing we can do

@samtstern
samtstern marked this pull request as ready for review October 14, 2020 12:06
@samtstern

Copy link
Copy Markdown
Contributor Author

@yuchenshi and @hiranya911 thank you both for your comments, I got the code into a much cleaner state where useEmulator is no longer passed down beyond Auth.

@hiranya911 hiranya911 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.

Thanks. This looks pretty good. Just a bunch of nits and cleanup suggestions. Lets use single quotes around string literals everywhere.

Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/token-generator.ts Outdated
Comment thread src/auth/token-verifier.ts Outdated
Comment thread src/auth/auth.ts Outdated
Comment thread src/auth/token-verifier.ts Outdated
Comment thread test/unit/auth/auth.spec.ts
Comment thread test/unit/auth/token-verifier.spec.ts Outdated
Comment thread src/auth/auth.ts Outdated
@samtstern
samtstern requested a review from hiranya911 October 14, 2020 18:35

@hiranya911 hiranya911 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.

Thanks. LGTM 👍

@hiranya911 hiranya911 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 a suggestion.

Comment thread src/auth/auth.ts
@yuchenshi
yuchenshi merged commit dbb0c78 into master Oct 16, 2020
@yuchenshi
yuchenshi deleted the ss-auth-emulator-support branch October 16, 2020 20:59
@hiranya911 hiranya911 changed the title Add support for Auth Emulator fix(auth): Add support for Auth Emulator Oct 20, 2020
@hiranya911 hiranya911 changed the title fix(auth): Add support for Auth Emulator feat(auth): Add support for Auth Emulator Oct 20, 2020
@joelpoloney

Copy link
Copy Markdown

❤️❤️❤️❤️❤️❤️

@nickreynke

Copy link
Copy Markdown

Thank you for implementing the emulator! Good work!

BorntraegerMarc pushed a commit to BorntraegerMarc/firebase-admin-node that referenced this pull request Jan 28, 2021
* Basic URL replacement and custom tokens

* Fix test

* Tests actually pass

* Mock verifyIdToken

* Add another test

* Small style change

* Small simplification

* Significant cleanup of all the useEmulator stuff

* Make sure we don't use env var to short-circuit ID Token verification

* Make lint pass

* Add unit tests that go through the Auth interface

* Hiranya nits

* Make private method even more private and scary, require env

* Make the private method throw

* Fix test
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.

5 participants