Skip to content

Instantly share code, notes, and snippets.

@MilesChou
Created November 4, 2019 15:17
Show Gist options
  • Save MilesChou/12cf0a14bec429a7fdea97063cfb0010 to your computer and use it in GitHub Desktop.
Save MilesChou/12cf0a14bec429a7fdea97063cfb0010 to your computer and use it in GitHub Desktop.
<?php
// See https://github.com/web-token/jwt-framework/tree/v1.3.9 for about JWT
function createAppleIDSecret()
{
$privateKey = file_get_contents('/path/to/your/key');
$keyId = 'key_id';
$teamId = 'team_id';
$clientId = 'client_id';
$jwk = JWKFactory::createFromKey($privateKey, null, [
'kid' => $keyId,
]);
$build = new JWSBuilder(null, new AlgorithmManager([
new ES256(),
]));
$arr = [
'aud' => 'https://appleid.apple.com',
'exp' => time() + 60,
'iat' => time(),
'iss' => $teamId,
'sub' => $clientId,
];
$jws = $build->withPayload(JsonConverter::encode($arr))
->addSignature($jwk, ['kid' => $keyId, 'alg' => 'ES256'])
->build();
return (new CompactSerializer())->serialize($jws);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment