400 invalid_grant when authenticating via Apple

Please provide the following:

  1. SDK Version: 38
  2. Platforms(Android/iOS/web/all): iOS

Hi everyone.

I use expo-apple-authentication for integrating with Apple Auth.
I’ve set everything up in Apple Dev console. I can successfully get a response from Apple by calling
AppleAuthentication.signInAsync as it mentioned in the documentation.

The problem occurs when I turn to the backend to convert Apple auth code to an internal token my app works with. For doing that, I send a request to an endpoint on my backend sending an authorization_code gotten from the Apple Auth.

Then my backend sends a request to https://appleid.apple.com/auth/token:

'client_id': <App ID>,
'client_secret': <client_secret>,
'code': <Code received from iOS app>,
'grant_type': 'authorization_code'

And I get 400 invalid_grant from Apple on the backend.

Is there anything I’m missing in the app or on the backend?
How to fix that out?