-
Notifications
You must be signed in to change notification settings - Fork 376
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
Defines TenantAwareAuth #551
Conversation
…nk APIs, OIDC/SAML provider config mgmt APIs.
…uth API requests. Adds detailed tenant mismatch error for uploadAccount on tenant Id mismatch for TenantAwareAuth.
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 pretty good. Just a few suggestions, and a question about the tests.
utils.getProjectId(auth.app), | ||
new TenantAwareAuthRequestHandler(auth.app, tenantId), | ||
cryptoSignerFromApp(auth.app)); | ||
utils.addReadonlyGetter(this, 'tenantId', tenantId); |
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.
Just mark the constructor argument as public readonly
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.
One problem with this is that if they are not using typescript, they can overwrite this without any error thrown. I tried it and the property can be overwritten. Since this is publicly available, i think we should enforce the readonly.
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.
I expected the TS compiler to generate a readonly getter for this, but looks like that only happens if we expose this as a getter in the code. So this is ok.
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.
I expected the TS compiler to add a readonly getter, but looks like that only happens if we define a getter explicitly here. So this is ok.
src/auth/auth.ts
Outdated
*/ | ||
export class Auth extends BaseAuth implements FirebaseServiceInterface { | ||
public INTERNAL: AuthInternals = new AuthInternals(); | ||
private tenantsMap: {[key: string]: TenantAwareAuth}; |
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.
readonly
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
test/unit/auth/auth.spec.ts
Outdated
mockCredentialAuth.verifyIdToken(mocks.generateIdToken()); | ||
}).to.throw(expected); | ||
}); | ||
it('should not throw on valid tenant ID', () => { |
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 is pretty much the same as the following test case. Consider removing it.
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
@@ -47,6 +49,15 @@ chai.use(chaiAsPromised); | |||
const expect = chai.expect; | |||
|
|||
|
|||
interface AuthTest { |
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 file is bit complicated to review. Can I assume it's just running the existing tests in 2 test configs, with the tests specific to an auth implementation enclosed in if-blocks?
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, I completely understand. This is the same GitHub diff issue. This should no longer be an issue in the next PRs.
You are mostly right. Same tests are run for both. There are cases where I add specific tests for tenant specific behavior. For example:
- createCustomToken should throw unsupported tenant operation error
- verifyIdToken with token missing or mismatching tenant ID
- verifySessionCookie with missing or mismatching tenant ID
- importUsers with explicit mismatching tenant IDs
- confirm createSessionCookie calls verifyIdToken before making call to create a session cookie
I do this by checking testConfig.Auth === TenantAwareAuth
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. Thanks.
utils.getProjectId(auth.app), | ||
new TenantAwareAuthRequestHandler(auth.app, tenantId), | ||
cryptoSignerFromApp(auth.app)); | ||
utils.addReadonlyGetter(this, 'tenantId', tenantId); |
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.
I expected the TS compiler to add a readonly getter, but looks like that only happens if we define a getter explicitly here. So this is ok.
Thanks for the review! |
Defines TenantAwareAuth and its user management APIs, email action link APIs, OIDC/SAML provider config mgmt APIs.