Sign In With Apple JS returns 'invalid_request: Invalid redirect_uri.'

Viewed 10512

I've started integrating Sign In With Apple to my website, but I'm having some issues. I THINK I've configured Sign In With Apple on their end as it should be.

Developer

Developer 2

Code

Next, I configured my HTML/CSS/JS as I saw on an article. When I click the "Sign In With Apple" button, it takes me to this screen:

enter image description here

I've been struggling with this for hours, what am I doing wrong?

Thanks, Jackson

6 Answers

I had the same problem. A few things tripped me up:

  1. In Apple Dev portal, your "Return URLs" need to have "https://", e.g. https://myawesomepwa.com. Meanwhile, the "domains and subdomains cannot have https; it must be the bare domain, e.g. myawesomepwa.com.

  2. Make sure all the URLs you specify don't have a trailing slash.

  3. In your JS code, make sure your redirect URL doesn't have a trailing slash:

Example JS code:

AppleID.auth.init({
    clientId : this.clientId,
    scope : "email",
    redirectURI : "https://myawesomepwa.com",
    state : "initial",
    usePopup : true
});

Once I did that, Sign in With Apple started working.

In my case the error message 'invalid_request: Invalid redirect_uri.' was badly misleading! The problem was that I did not create a Key in "Certificates, Identifiers & Profiles/Keys".

So: Click + to create a new Key -> Enter a name and check Sign in with Apple -> Click configure button next to the checkbox -> select your Primary App ID.

I followed this tutorial: Sign In with Apple: Learn About the New Identity Provider

Seems like you have solved it, I think the issue was the trailing slash on the redirect_uri, removing it might solve this issue.

I was getting the same error because I had some query strings like ?param=dynamic.value.

The error was gone by removing the query strings.

I was able to pass the dynamic value this way:

state: JSON.stringify({ param: 'dynamic.value' })

tl;dr : just try to create a new Service ID from the Apple Console.

I was getting this issue, created a new Service IDs from the Apple Configuration with the right config and got it working.
I remember I made a typo when I first created it and update the endpoint just afterwards. The update wasn't took into account.
Check you current URL setup with the service with the "Copy to Clipboard" Button. You will see a typo in your URL for sure.

Please make a new Identifier if there's already existing.

Related