0

I am working with fedcm api for authentication. I am using this

if ('IdentityCredential' in window) {
    // AJAX call to login
    navigator.login.setStatus('logged-in');


    // TODO handle user canceling
    const credential = await navigator.credentials.get({
        identity: {
            // Specify the IdP (or multiple IdPs, supported from Chrome 136) this Relying Party supports
            providers: [
                {
                    configURL: 'https://accounts.google.com/gsi/fedcm.json',        
                    clientId: '<my-client-id>',
                    nonce: crypto.randomUUID() 
                }
            ]
        }
    });
    console.log(credential);
}

and the client id has 2 URL's in the authorized JS domains. One is a public https server i am running. When I test this there, it works ok and I get the credential. But when I run this on localhost:3000, and I have http://localhost:3000 in the authorized JS domain, i still get

The fetch of the id assertion endpoint resulted in a network error: ERR_FAILED
localhost/:1 Server did not send the correct CORS headers.
main.js:26 Uncaught (in promise) IdentityCredential
Error: Error retrieving a token.

how do I get this to work?

1
  • 1
    Check if your client config contains both http://localhost and http://localhost:3000, and that your referrer policy is set correctly - stackoverflow.com/a/78494068/1427878 Commented May 27 at 9:36

1 Answer 1

0

If it works in a different enviroment but not in localhost may be due to chrome configuration that is not allowing pop-ups from localhost.

Try navigating to chrome://settings/content/federatedIdentityApi and enabling Third-party sign-in

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.