I'm facing issues for sign in with the apple. I go through many blogs and official documentation but nothing works.
The flow of my application is the same as mentioned in the documentation: Application will send authorization code to the backend server, backend server generates a client secret and it will send it to the apple server in order to get access_token.
Getting the same response every time:
response: {"error: "invalid_client"}
So here is my code:
Generating client_secret
used jsonwebtoken package.
let client_secret = jwt.sign({}, privateToken, {
algorithm: 'ES256',
expiresIn: 1578513833,
audience: "https://appleid.apple.com",
subject: process.env.APPLE_CLIENT_ID,
issuer: process.env.ISS,
keyid: process.env.KID
});
Payload to send to apple server
let body = {
client_id: process.env.APPLE_CLIENT_ID,
client_secret: client_secret,
code: authorize_code,
grant_type: 'authorization_code'
}
Request to apple server
let appleResponse = await axios.post(
'https://appleid.apple.com/auth/token',
queryString.stringify(body), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
Can anyone please help me to solve this error.
Thank you in advance.