Created
November 4, 2019 15:17
-
-
Save MilesChou/12cf0a14bec429a7fdea97063cfb0010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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