Hi again! I'm trying to to do signinup with apple...
# support-questions-legacy
k
Hi again! I'm trying to to do signinup with apple, as I have google working. When I do the same with Apple, it throws an error on the backend.
Copy code
javascript
console.log(credential.authorizationCode);

      await axios
        .post(
          `${API_DOMAIN}/auth/signinup`,
          {
            redirectURI: "com.demoapp:/oauthredirect",
            thirdPartyId: "apple",
            code: credential.authorizationCode,
            clientId: MY CLIENT ID.
          },
          {
            headers: {
              rid: "thirdpartyemailpassword",
            },
          }
        )
r
@nkshah2 can help with this.
k
Thank you!
Copy code
javascript
providers: [
        Apple({
          isDefault: true,
          clientId: "com.killiansmith.runin",
          clientSecret: {
            keyId: process.env.APPLE_KEY_ID!,
            privateKey: process.env.APPLE_PRIVATE_KEY!,
            teamId: process.env.APPLE_TEAM_ID!,
          },
        }),
        ...
That is the backend
n
Hey @killian.s can you print the full response you received from the signinup API?
k
.catch((error) => { console.log(error.response); }); console.log(result); Is that what you are looking for?
n
Yep can you also print the full request body
k
On the server?
n
Or on the client, either works
k
I think that is it
I also tried it in Postman and got the same result
n
Is the client id for a service id or an app id on the apple developer portal?
k
I think it's for the app
n
Can you click on the edit button next to sign in with apple
Send a screenshot of that as well
k
Also got it as a key
n
Right so in our example app: https://github.com/supertokens/supertokens-react-native/blob/master/examples/with-thirdpartyemailpassword/apple.js We use the key configuration as the client id for iOS (The AppId flow only works for iOS and other apple platforms)
Copy code
let signInUpResponse = await axios.post(
            `${API_DOMAIN}/auth/signinup`,
            {
                redirectURI: "com.demoapp:/oauthredirect",
                thirdPartyId: "apple",
                code: authCode,
                clientId: "4398792-io.supertokens.example"
            },
            {
                headers: {
                    rid: "thirdpartyemailpassword"
                }
            }
        );
Can you try that?
k
Still the same
Copy code
javascript
console.log(credential.authorizationCode);

      let signInUpResponse = await axios
        .post(
          `${API_DOMAIN}/auth/signinup`,
          {
            redirectURI: "com.demoapp:/oauthredirect",
            thirdPartyId: "apple",
            code: credential.authorizationCode,
            clientId: "4398792-io.supertokens.example",
          },
          {
            headers: {
              rid: "thirdpartyemailpassword",
            },
          }
        )
        .catch((error) => {
          console.log(error.response.body);
        });

      console.log(signInUpResponse);
n
No you need to use the key configuration for your app from the screenshot you sent
From this one
k
Ah my bad, sorry
Like so?
n
Yep
k
Still got the same result
n
Are you using express for your backend?
k
Yeah
n
In the default error handler can you print the full error
k
Is it the error handler that comes with Supertokens?
app.use(errorHandler());
n
No I meant the part that handles errors for your server
Copy code
app.use((err, req, res, next) => {...})
Looks similar to this
k
That is how I got the result
n
Ok, can you try using your bundle identifier as the client id for both the frontend and the backend and print the full error again on your server
k
Apple({ isDefault: true, clientId: "BG8TG3D6YB.com.killiansmith.runin", clientSecret: { keyId: process.env.APPLE_KEY_ID!, privateKey: process.env.APPLE_PRIVATE_KEY!, teamId: process.env.APPLE_TEAM_ID!, }, }),
Like that?
n
Whats the bundle identifier for the iOS version of your app? (Youll have to check this inside Xcode)
k
It's an expo application, so It is set to com.killiansmith.runin
Also the signing in with Apple part seems to work, which is good
It just doesn't interact with supertokens
n
Right so use
com.killiansmith.runin
as the client id for the backend and frontend and print the full error on the server
Basically what you tried initially, just this time printing the error
k
data: { error: 'invalid_grant', error_description: 'client_id mismatch. The code was not issued to com.killiansmith.runin.' }
Would you like the whole message?
n
No thats alright
Can you show the contents of the expo app.js config?
k
"ios": { "supportsTablet": true, "bundleIdentifier": "com.killiansmith.runin" },
Yeah there is the IOS part
n
Are you running on a simulator by chance?
k
Yes...
n
Is it possible for you to run on a device?
k
No I don't own an iPhone, I think I can build the app and run it though
n
So Apple is known to give invalid codes and tokens on simulators, which breaks the flow when SuperTokens uses the code to fetch user information. If you can test on a device or build for Testflight and then check on someone elses device we can rule that out
Your configuration looks fine otherwise so it most likely is a simulator issue
k
Oh wow I didn't know that, that sucks :(
Thanks Apple
n
Yep, thanks Apple indeed. But yeah actually trying it out would tell us more, if you can build for Testflight I could join the testers and try it out for you if that makes it easier
k
Yeah, thank you! I'll try and build the app, and I'll let you know
@nkshah2. I found out why it wasn't working. When expo is in development the client id is expo.client.io (or something like that). So I was trying to log in with an invalid Client id. I built the app in development mode and it works!
Thank you for help!
n
Oh awesome, glad you could make it work! Strange that expo does not honor the bundle id you set in your config in dev mode but yeah thats useful to know for future issues too
2 Views