Skip to content

feat(auth): Emulator support for CreateCustomTokenAsync() API#293

Merged
hiranya911 merged 3 commits into
auth-emulatorfrom
hkj-customtoken-emulator
Apr 8, 2021
Merged

feat(auth): Emulator support for CreateCustomTokenAsync() API#293
hiranya911 merged 3 commits into
auth-emulatorfrom
hkj-customtoken-emulator

Conversation

@hiranya911

Copy link
Copy Markdown
Contributor

Implemented support for creating custom tokens for the emulator. In the emulator mode:

  • The alg header is set to none.
  • Signature is set to empty byte sequence.

Bulk of the changes are just refactoring the existing tests. I've updated CustomTokenTest to be more inline with other test classes like IdTokenVerificationTest, where we test behavior via parameterization, as opposed to creating FirebaseApp instances with different configurations.

@lahirumaramba lahirumaramba 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!
Is there a kid in the header for emulator tokens?

Comment thread FirebaseAdmin/FirebaseAdmin/Auth/Jwt/EmulatorSigner.cs Outdated
@hiranya911

Copy link
Copy Markdown
Contributor Author

Custom tokens don't use a kid header regardless of the method used to sign.

@hiranya911 hiranya911 merged commit 8dd59fa into auth-emulator Apr 8, 2021
@hiranya911 hiranya911 deleted the hkj-customtoken-emulator branch April 8, 2021 20:08
hiranya911 added a commit that referenced this pull request Apr 13, 2021
* feat(auth): Add support for Firebase Authentication Emulator (#289)

* Add IdToolkitHostResolver with tests

* Add resolution for versions of the API with tests

* Simplify and reduce IdToolkitHostResolver to a Util method

* Add TestConfig for testing against FirebaseEmulatorHost

Add environment variable test that piggybacks on the already established
FirebaseUserManagerTest.

Also, to make it easier to access and set environment variables a
convenience class has been made to help out. This class utilizes the
neat builtin get and set mechanism provided by the C# language. By using
this class the code somewhat documents itself and prevents stupid
spelling mistakes that might occur when running code. Each environment
variable can conveniently be documented inside the class.

* Add license for new Utils class file

* Add documentation for ResolveIdToolkitHost with examples

* Use the EnvironmentVariable class to access env variables

* Fix formatting

* Use inheritance instead of TestConfig to set FirebaseUserManager tests

The TestConfig was not being disposed of when expected resulting in
the env variable being set in other tests as well and causing them to
fail.

* Cleanup and rename variable to more meaningful name

* Move Utils and EnvironmentVariable class to Auth namespace

* Move emulatorHostEnvVar to where it's used for readability

* Rename UtilTest to more appropriate name

* Rename expected...Host to expected...Url

* Use the FirebaseAuthEmulatorHostName const instead of string

* Add missing license head

* Add missing util import and fix stylecop complaints

* Rename AuthUtil to Util and move to Auth test folder

* Simplify emulator host environment variable to be a constant in Utils

* Use string literal for emulator host in FirebaseUserManagerTest

In case a constant values is changed such as the used environment
variable, this will cause the tests to fail, which is good to know.

* Remove unnecessary tests from FirebaseAuthTest

* Use string literal to ensure test fails if constant is changed

* Remove the environment simplification since there is only one callsite

* Cleanup GetIdToolkitHost documentation

* Correct typo in file name. Util -> Utils.

* Rename test cass to UtilsTest

* Add tenant resolution to GetIdToolkitHost

* Add function for resolving GoogleCredentials when in emulator mode

* Add test for tenant url resolution

* Use if statement instead of ternary for tenantIdPath

* Better formatting for GetIdToolkitHost

* Add periods to the end of documentation strings

* Remove nullable and provide empty string instead

* Change to only have one single line at end

* Add convenience funcs for getting and checking emulator host env variable

* Simplify GetEmulatorHost name

* fix(auth): Setting EmulatorHost programatically (#290)

* fix(auth): Setting EmulatorHost programatically

* fix: Cleaned up tests

* fix: Cleaned up user manager tests

* feat(auth): Supporting VerifyIdToken() API with emulator (#291)

* feat(auth): Emulator support for CreateCustomTokenAsync() API (#293)

* feat(auth): Emulator support for CreateCustomTokenAsync() API

* fix: Cleaned up unit tests

* fix: Removed extra punctuation

* feat(auth): Adding emulator support to TenantManager API (#294)

* feat(auth): Adding emulator support to TenantManager API

* fix: Updated test to check for credentials

Co-authored-by: Bjarke <work.bjarke@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants