-
Notifications
You must be signed in to change notification settings - Fork 939
Implement getToken method for Regional Auth Interop #9061
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
Open
mansisampat
wants to merge
12
commits into
gcip-byociam-web
Choose a base branch
from
sammansi-gcip-interop
base: gcip-byociam-web
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
28c985d
Write Firebase Token to Auth instance
mansisampat df70b65
yarn run format
mansisampat f1509da
Fix unit test and run yarn docgen:all
mansisampat 817f8be
getFirebaseToken Auth Interop method for BYO-CIAM
mansisampat ea7b605
Add unit test
mansisampat 0f7032f
Adding Unit test
mansisampat a5a79f1
Running yarn docgen:all
mansisampat c8d9cb5
Use getToken instead of getFirebaseToken
mansisampat 205916f
Adding Unit test
mansisampat 94d1913
yarn run format
mansisampat b6e9a9e
Remove unused method
mansisampat b9d36c9
Merge branch 'gcip-byociam-web' into sammansi-gcip-interop
mansisampat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Project: /docs/reference/js/_project.yaml | ||
Book: /docs/reference/_book.yaml | ||
page_type: reference | ||
|
||
{% comment %} | ||
DO NOT EDIT THIS FILE! | ||
This is generated by the JS SDK team, and any local changes will be | ||
overwritten. Changes should be made in the source code at | ||
https://github.com/firebase/firebase-js-sdk | ||
{% endcomment %} | ||
|
||
# FirebaseToken interface | ||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface FirebaseToken | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [expirationTime](./auth.firebasetoken.md#firebasetokenexpirationtime) | number | | | ||
| [token](./auth.firebasetoken.md#firebasetokentoken) | string | | | ||
|
||
## FirebaseToken.expirationTime | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly expirationTime: number; | ||
``` | ||
|
||
## FirebaseToken.token | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly token: string; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ interface TokenListener { | |
} | ||
|
||
export class AuthInterop implements FirebaseAuthInternal { | ||
private readonly TOKEN_EXPIRATION_BUFFER = 30_000; | ||
private readonly internalListeners: Map<TokenListener, Unsubscribe> = | ||
new Map(); | ||
|
||
|
@@ -51,6 +52,27 @@ export class AuthInterop implements FirebaseAuthInternal { | |
return { accessToken }; | ||
} | ||
|
||
async getFirebaseToken(): Promise<{ accessToken: string } | null> { | ||
this.assertAuthConfigured(); | ||
await this.auth._initializationPromise; | ||
this.assertRegionalAuthConfigured(); | ||
if (!this.auth.firebaseToken) { | ||
return null; | ||
} | ||
|
||
if ( | ||
!this.auth.firebaseToken.expirationTime || | ||
Date.now() > | ||
this.auth.firebaseToken.expirationTime - this.TOKEN_EXPIRATION_BUFFER | ||
) { | ||
await this.auth._updateFirebaseToken(null); | ||
return null; | ||
} | ||
|
||
const accessToken = await this.auth.firebaseToken.token; | ||
return { accessToken }; | ||
} | ||
|
||
addAuthTokenListener(listener: TokenListener): void { | ||
this.assertAuthConfigured(); | ||
if (this.internalListeners.has(listener)) { | ||
|
@@ -85,6 +107,10 @@ export class AuthInterop implements FirebaseAuthInternal { | |
); | ||
} | ||
|
||
private assertRegionalAuthConfigured(): void { | ||
_assert(this.auth.tenantConfig, AuthErrorCode.OPERATION_NOT_ALLOWED); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required with new changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed unused methods. |
||
|
||
private updateProactiveRefresh(): void { | ||
if (this.internalListeners.size > 0) { | ||
this.auth._startProactiveRefresh(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't we use the existing getToken method instead of new? If we create new, then wouldn't the existing product logic have to make changes?
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.
In that case we would have to force that getToken method should have forceRefresh as false if regional auth is initialized.
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.
Yes, that would be the case as refreshToken is not supported. Alternatively we can log a warning message and ignore the field for now, but i would prefer throwing error as it makes it more clear.