-
Notifications
You must be signed in to change notification settings - Fork 8
Fix FedCM issue caused by the recent breaking change #104
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
agektmr
wants to merge
3
commits into
main
Choose a base branch
from
fedcm-fix
base: main
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| import {$, post} from '~project-sesame/client/helpers/index'; | ||
| import {saveFederation} from '~project-sesame/client/helpers/federated'; | ||
|
|
||
| /** | ||
| * Options for FedCM authentication and delegation. | ||
| */ | ||
| export interface FedCmOptions { | ||
| mode?: 'active' | 'passive'; | ||
| loginHint?: string; | ||
|
|
@@ -32,20 +35,36 @@ export interface FedCmOptions { | |
| // This is almost identical to the IdentityProvider class at https://sesame-identity-provider.appspot.com/fedcm.js. | ||
| // Copied here since some integration needs custom implementation on the RP side. | ||
| // ex: unified auth with password, multiple IdPs, etc. | ||
| /** | ||
| * Helper class for interacting with the Identity Provider (IdP) via FedCM. | ||
| * This class handles initialization, sign-in, and attribute delegation. | ||
| */ | ||
| export class SesameIdP { | ||
| /** List of IdP URLs to initialize with. */ | ||
| urls: string[] = []; | ||
|
|
||
| /** List of resolved IdP configurations. */ | ||
| idps: { | ||
| origin: string; | ||
| configURL: string; | ||
| clientId: string; | ||
| }[] = []; | ||
|
|
||
| /** | ||
| * Creates an instance of SesameIdP. | ||
| * @param urls List of IdP URLs to initialize with. | ||
| */ | ||
| constructor(urls: string[] = []) { | ||
| for (const url of urls) { | ||
| this.urls.push(new URL(url).toString()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Initializes the IdP by fetching configuration options from the server. | ||
| * Resolves the config URLs and client IDs for each IdP. | ||
| * @returns The nonce to be used for authentication. | ||
| */ | ||
| async initialize() { | ||
| const options = await post('/federation/options', { | ||
| urls: this.urls, | ||
|
|
@@ -63,9 +82,14 @@ export class SesameIdP { | |
| }; | ||
| this.idps.push(idp); | ||
| } | ||
| return options.nonce; | ||
| return; | ||
|
Collaborator
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. Should there be a return value here? If not, just remove the |
||
| } | ||
|
|
||
| /** | ||
| * Performs the FedCM sign-in flow. | ||
| * @param options Configuration options for the sign-in request. | ||
| * @returns A promise that resolves to the verified user object or undefined. | ||
| */ | ||
| async signIn( | ||
| options: FedCmOptions = {} | ||
| // @ts-ignore | ||
|
|
@@ -91,10 +115,9 @@ export class SesameIdP { | |
| providers.push({ | ||
| configURL: idp.configURL, | ||
| clientId: idp.clientId, | ||
| nonce, | ||
| loginHint, | ||
| fields, | ||
| params, | ||
| params: { nonce, ...params }, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -121,6 +144,11 @@ export class SesameIdP { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Performs the FedCM delegation flow (Verifiable Credentials / SD-JWT). | ||
| * @param options Configuration options for the delegation request. | ||
| * @returns A promise that resolves to the verified token or undefined. | ||
| */ | ||
| async delegate(options: FedCmOptions = {}): Promise<string | undefined> { | ||
| let {mode = '', nonce, fields, mediation, params = {}} = options; | ||
| if (!nonce) { | ||
|
|
@@ -136,9 +164,8 @@ export class SesameIdP { | |
| format: 'vc+sd-jwt', | ||
| configURL: idp.configURL, | ||
| clientId: idp.clientId, | ||
| nonce, | ||
| fields, | ||
| params, | ||
| params: { nonce, ...params }, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -151,6 +178,11 @@ export class SesameIdP { | |
| return await this.verifySdJwt(cred); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies the ID token with the backend and saves the federation status. | ||
| * @param cred The IdentityCredential returned by navigator.credentials.get. | ||
| * @returns The verified user object. | ||
| */ | ||
| // @ts-ignore | ||
| private async verifyIdToken(cred: IdentityCredential): User { | ||
| const idp = this.idps.find(idp => { | ||
|
|
@@ -171,6 +203,11 @@ export class SesameIdP { | |
| return user; | ||
| } | ||
|
|
||
| /** | ||
| * Verifies the SD-JWT with the backend. | ||
| * @param cred The IdentityCredential returned by navigator.credentials.get. | ||
| * @returns The verified user object or token. | ||
| */ | ||
| // @ts-ignore | ||
| private async verifySdJwt(cred: IdentityCredential): User { | ||
| const idp = this.idps.find(idp => { | ||
|
|
@@ -189,6 +226,9 @@ export class SesameIdP { | |
| }); | ||
| return user; | ||
| } | ||
| /** | ||
| * Signs out the user by preventing silent access. | ||
| */ | ||
| async signOut() { | ||
| if (navigator.credentials && navigator.credentials.preventSilentAccess) { | ||
| await navigator.credentials.preventSilentAccess(); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
|
|
||
| import '~project-sesame/client/layout'; | ||
| import { | ||
| $, | ||
| redirect, | ||
| postForm, | ||
| toast, | ||
|
|
||
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.
New hint has been added for a return value, but the function does not return it.