-
Notifications
You must be signed in to change notification settings - Fork 274
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
<pwa-auth>
– enable Sign in with Google with a reduced response when strict privacy mode (Block third-party cookies or InPrivate browsing) is used (until we switch to Google Identity Services for Web).
#3343
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e7f898e
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert f0bdfe7
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert 1e202d3
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert 18cb4ff
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert 867e823
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert 218c6f2
Temporarily address #3286 to enable Sign in with Google with a reduce…
CetinSert 52b2c0b
Correctly handle cancelling the flow by closing the popup more than once
CetinSert 99d67f7
refactor internal helper `matchingEvent` → `event`
CetinSert 2ee9fda
handle cancellations when third-party cancellations are *not* blocked.
CetinSert 59332e6
remove console.warn() calls
CetinSert 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 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,6 +1,21 @@ | ||
import { SignInResult } from "./signin-result"; | ||
import { SignInProvider } from "./signin-provider"; | ||
|
||
const JP = (...a) => { try { return JSON.parse(...a); } catch (_) { return undefined; } }; | ||
|
||
const any = AbortSignal.any ?? (S => { | ||
const C = new AbortController(); for (const s of S) { if (s === undefined) continue; if (s.aborted) { C.abort(); break; } s.addEventListener('abort', () => C.abort(), { once: true, signal: C.signal }); } | ||
return C.signal; | ||
}); | ||
|
||
const event = (name, { source: on = globalThis, map = x => x, find = e => true, signal, default: { value: V, error: E } = {} } = {}) => new Promise(async (Y, N) => { const s = signal; const A = new AbortController(); | ||
const a = async () => (V === undefined ? N(E) : Y(await V) ); if (s?.aborted) return (A.abort(), a()); s?.addEventListener?.('abort', a, { once: true }); | ||
const l = async e => { e = map(e); if (!find(e)) return; A.abort(); Y(await e); }; on.addEventListener (name, l, { signal: any([ s, A.signal ]) }); | ||
}); | ||
|
||
const wait = {}; | ||
|
||
|
||
export class GoogleProvider implements SignInProvider { | ||
|
||
static readonly apiUrl = "https://apis.google.com/js/api:client.js"; | ||
|
@@ -66,8 +81,30 @@ export class GoogleProvider implements SignInProvider { | |
} | ||
|
||
// Otherwise, kick off the OAuth flow. | ||
return auth.signIn() | ||
.then(user => this.getSignInResultFromUser(user)); | ||
// (Use only a reduced response when people Block third-party cookies or use InPrivate browsing.) | ||
const I = auth.signIn(); | ||
const Y = async signal => { | ||
const z = await event('message', { signal, map: e => JP(e.data), find: d => d?.params?.type == 'authResult' }); | ||
const id_token = z.params.authResult.id_token; | ||
const j = await fetch(`https://oauth2.googleapis.com/tokeninfo?${new URLSearchParams({ id_token })}`).then(f => f.json()); | ||
const x = { | ||
email: j.email, | ||
idToken: id_token, | ||
provider: 'Google', | ||
error: null, | ||
providerData: j | ||
}; | ||
try { return this.getSignInResultFromUser(await I); } | ||
catch (q) { return x ; } | ||
}; | ||
const N = async signal => { event('message', { signal, map: e => JP(e.data), find: d => d?.params?.type == 'idpError' }).then(_ => wait.twice = true); | ||
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.
{
"method": "fireIdpEvent",
"params": {
"type": "idpError",
"error": "Cookies are not enabled in current environment."
},
"rpcToken": "1227886743.6877475"
}, |
||
/**/ let e; e = await event('error', { signal }); | ||
if (wait.twice) { wait.twice = false; e = await event('error', { signal }); } | ||
throw new Error('User cancelled the flow!'); | ||
}; | ||
let E; const C = new AbortController(); | ||
let R; try { R = await Promise.race([ Y(C.signal), N(C.signal) ]); } catch (e) { E = e; }; C.abort(); if (E !== undefined) throw E; | ||
return R; | ||
} | ||
|
||
private getSignInResultFromUser(user: gapi.auth2.GoogleUser): SignInResult { | ||
|
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.
e.data