first of all, I’m not very good at English, so I’m using a translator to ask my question. Please understand if my question sounds strange.
I’m implementing Apple SNS login for the web, and at first, I tried using this code:
const clientSecret = jwt.sign(
{
iss: process.env.APPLE_TEAM_ID,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
aud: `https://appleid.apple.com`,
sub: process.env.APPLE_CLIENT_ID
},
privateKey,
{
algorithm: 'ES256',
keyid: process.env.APPLE_KEY_ID,
}
);
However, I kept encountering the 'invalid_client' error.
After repeatedly asking ChatGPT for help, I got this code, which I’m currently using:
const clientSecret = jwt.sign({}, privateKey, {
algorithm: 'ES256',
expiresIn: '1h',
audience: 'https://appleid.apple.com',
issuer: `${process.env.APPLE_TEAM_ID}`,
subject: `${process.env.APPLE_CLIENT_ID}`,
keyid: `${process.env.APPLE_KEY_ID}`,
});
This version works without errors.
But I just can’t understand the difference between these two codes. Why didn’t the first version work, even though I included the payload values as required…?