Skip to content

Commit 6958370

Browse files
authored
Merge pull request #25 from GoogleChromeLabs/fedcm-passive-remove-local-idp
FedCM passive mode: add the local IdP only if developing in local env
2 parents 51608c3 + 1e9ec14 commit 6958370

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/client/helpers/federated.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@ export async function saveFederation(
8787
export async function getAllIdentityProviders(): Promise<any> {
8888
return get('/federation/mappings');
8989
}
90+
91+
/**
92+
* Returns a list of IdP URLs based on the environment.
93+
*/
94+
export async function getIdpUrls(): Promise<string[]> {
95+
return get('/federation/idp-list');
96+
}

src/client/pages/fedcm-passive-mode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
toast,
2424
} from '~project-sesame/client/helpers/index';
2525
import {SesameIdP} from '~project-sesame/client/helpers/identity';
26+
import { getIdpUrls } from '../helpers/federated';
2627

2728
postForm(
2829
async () => {
@@ -37,11 +38,8 @@ postForm(
3738
if ('IdentityCredential' in window) {
3839
$('#unsupported').classList.add('hidden');
3940
try {
40-
const idp = new SesameIdP([
41-
'https://sesame-identity-provider.appspot.com',
42-
'https://accounts.google.com',
43-
'https://sesame-identity-provider.local'
44-
]);
41+
const idpURLs = await getIdpUrls();
42+
const idp = new SesameIdP(idpURLs);
4543
const nonce = await idp.initialize();
4644
await idp.signIn({mode: 'passive', mediation: 'required', nonce});
4745
await redirect('/home');

src/server/middlewares/federation.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,25 @@ router.post(
290290
}
291291
);
292292

293+
/**
294+
* Returns a list of IdP URLs based on the environment.
295+
*/
296+
router.get(
297+
'/idp-list',
298+
apiAclCheck(ApiType.NoAuth),
299+
(req: Request, res: Response) => {
300+
const idpUrls = [
301+
'https://sesame-identity-provider.appspot.com',
302+
'https://accounts.google.com',
303+
];
304+
305+
if (config.is_localhost) {
306+
// TODO: Ideally, let's wrap it in one place to reuse elsewhere
307+
idpUrls.push("https://sesame-identity-provider.local");
308+
}
309+
310+
return res.json(idpUrls);
311+
}
312+
);
313+
293314
export {router as federation};

0 commit comments

Comments
 (0)