passport-apple inexplainable invalid_client on nodejs backend -- using clean example repository with fresh set of credentials

Viewed 377

I've cloned https://github.com/ananay/passport-apple-example and replaced the config with this:

clientID: "com.myname.web",
teamID: "myteamid",
callbackURL: "https://myurldev.com/auth/apple/redirect",
keyID: "mykeyid",
privateKeyLocation: path.join(__dirname, "../apple-key.p8")

I've also added SSL certificate on my machine and starting the server with https, all works fine & is recognized by my browser. I'm also starting the app on port 443 and proxying using my hosts file myurl.dev.com -> 127.0.0.1.

I have the same auth setup for facebook, google & microsoft and everything works fine.

I have:

  • Created a new APP identifier and enabled Sign in with Apple for it, named it: com.myname.dev
  • Created a new SERVICE identifier and enabled Sign in with apple, called it: com.myname.web
  • Added "https://myurldev.com/auth/apple/redirect" to the "Reply URLS" on the service identifier com.myname.web
  • Set my app identifier com.myname.dev as the main app identifier my service to be grouped with.
  • Created a private key and enabled sign in with apple, interface confirmed the presence of grouped ID com.myname.web bundled with com.myname.dev for which the key was created.
  • I have confirmed using console.log that the private key is indeed at the path being passed as parameter.
  • converted the .p8 file to base64 & then back to UTF-8 in an attempt to use the string for privateKeyString
  • successfully implemented Apple Oauth several times in the past using passport-apple

This time around, for some reason, auth simply doesn't work.

If I set the clientID as the APP identifier, not the service, I'm getting

invalid_request
Invalid web redirect url. 

instead of invalid_client

Any advice on debugging this is highly appreciated. Thank you.


EDIT #1:

I have dug a bit deeper into the passport-apple package to figure out if anything goes against apple's docs around token generation, but the flow never reaches that part, indicating things go wrong on the actual configuration in Apple's console & what I'm trying to use for my project.


EDIT #2 2 of the app Ids I have created always throw "wrong redirect uri" because they're not service IDs so I can't configure redirect_uri, this will change if to "required" if I pass undefined as a redirect_uri.

One of the app ids throws only invalid client_id instead, regardless if I pass undefined or good value for redirect_uri.


EDIT #3 Went full vanilla through the OAuth code flow process and just created a url & redirected the user it, failing with this method is consistent with what is happening when using the passport-apple module.


    const url = new URL("https://appleid.apple.com/auth/authorize");

    url.searchParams.append("state", "fdbd287b1f");
    url.searchParams.append("response_type", "code");
    url.searchParams.append("scope", "name email");
    url.searchParams.append("response_mode", "form_post");
    url.searchParams.append(
      "redirect_uri",
      "https://raiseitupdev.com/auth/apple/redirect",
    );
    url.searchParams.append("client_id", "com.myname.web");

    return res.redirect(url.toString());
1 Answers
Related