-
Notifications
You must be signed in to change notification settings - Fork 990
Auth cookie persistence #8839
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
Merged
Merged
Auth cookie persistence #8839
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d3792b5
First.
jamesdaniels 00b0059
Merge branch 'main' into jamesdaniels_authCookiePersistence
jamesdaniels aba574a
First.
jamesdaniels 8acd061
Sentinal as ""
jamesdaniels a727dce
Cleanup and add cookieStore fallback
jamesdaniels 769624f
Cleanup unsubscribes
jamesdaniels 31cb8b0
Cleanup and add docs
jamesdaniels 0bef1eb
Cleanup and add docs
jamesdaniels efdafc5
Changeset
jamesdaniels da747d7
Beta tag
jamesdaniels 27c203a
Merge branch 'main' into jamesdaniels_authCookiePersistence
jamesdaniels 7f850fc
Remove unneeded changes
jamesdaniels f587178
Address feedback, cleanup endpoint check
jamesdaniels 5568a01
Formatting
jamesdaniels 0ac4cad
Cleanup
jamesdaniels d278dcf
Tweak wording for doc
jamesdaniels fc1ce03
Code format COOKIE
jamesdaniels 6acbb6a
Formatting
jamesdaniels 8f97100
Cleanup
jamesdaniels 3291f23
Formatting
jamesdaniels 0fb3804
Update docs
jamesdaniels bdeeead
Fix test
jamesdaniels 5a913c9
Comments!
jamesdaniels d3fa466
Fix for the auth race condition
jamesdaniels 680583e
Address erics feedback
jamesdaniels 1e50af6
Forgot to commit the actual source file
jamesdaniels 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
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
82 changes: 82 additions & 0 deletions
82
packages/auth/src/platform_browser/persistence/cookie_storage.ts
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,82 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2019 Google LLC | ||
jamesdaniels marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Persistence } from '../../model/public_types'; | ||
|
|
||
| import { | ||
| PersistenceInternal, | ||
| PersistenceType, | ||
| PersistenceValue, | ||
| StorageEventListener | ||
| } from '../../core/persistence'; | ||
|
|
||
| export class CookiePersistence implements PersistenceInternal { | ||
| static type: 'COOKIE' = 'COOKIE'; | ||
| readonly type = PersistenceType.COOKIE; | ||
| listeners: Map<StorageEventListener, (e: any) => void> = new Map(); | ||
jamesdaniels marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| async _isAvailable(): Promise<boolean> { | ||
jamesdaniels marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return navigator.hasOwnProperty('cookieEnabled') ? | ||
jamesdaniels marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| navigator.cookieEnabled : | ||
| true; | ||
| } | ||
|
|
||
| async _set(_key: string, _value: PersistenceValue): Promise<void> { | ||
| return; | ||
| } | ||
|
|
||
| async _get<T extends PersistenceValue>(key: string): Promise<T | null> { | ||
| const cookie = await (window as any).cookieStore.get(key); | ||
| return cookie?.value; | ||
| } | ||
|
|
||
| async _remove(key: string): Promise<void> { | ||
jamesdaniels marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const cookie = await (window as any).cookieStore.get(key); | ||
| if (!cookie) { | ||
| return; | ||
| } | ||
| await (window as any).cookieStore.set({ ...cookie, value: "" }); | ||
| await fetch(`/__cookies__`, { method: 'DELETE' }).catch(() => undefined); | ||
| } | ||
|
|
||
| _addListener(_key: string, _listener: StorageEventListener): void { | ||
| // TODO fallback to polling if cookieStore is not available | ||
| const cb = (event: any) => { | ||
|
Check failure on line 58 in packages/auth/src/platform_browser/persistence/cookie_storage.ts
|
||
| const cookie = event.changed.find((change: any) => change.name === _key); | ||
| if (cookie) { | ||
| _listener(cookie.value); | ||
| } | ||
| }; | ||
| this.listeners.set(_listener, cb); | ||
| (window as any).cookieStore.addEventListener('change', cb); | ||
| } | ||
|
|
||
| _removeListener(_key: string, _listener: StorageEventListener): void { | ||
| const cb = this.listeners.get(_listener); | ||
| if (!cb) { | ||
| return; | ||
| } | ||
| (window as any).cookieStore.removeEventListener('change', cb); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * An implementation of {@link Persistence} of type 'NONE'. | ||
jamesdaniels marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @public | ||
| */ | ||
| export const cookiePersistence: Persistence = CookiePersistence; | ||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "extends": "../../config/api-extractor.json", | ||
| // Point it to your entry point d.ts file. | ||
| "mainEntryPointFilePath": "<projectFolder>/dist/rules-unit-testing/index.d.ts" | ||
| "mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts" | ||
jamesdaniels marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.