create() ->withPayload(json_encode([ 'iat' => time(), 'exp' => time() + 3600, 'iss' => $teamId, 'aud' => 'https://appleid.apple.com', 'sub' => $clientId ])) ->addSignature(JWKFactory::createFromKeyFile($keyFileName), [ 'alg' => 'ES256', 'kid' => $keyFileId ]) ->build(); $serializer = new CompactSerializer(); $token = $serializer->serialize($jws, 0); $data = [ 'client_id' => $clientId, 'client_secret' => $token, 'code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => $redirectUri ]; $ch = curl_init(); curl_setopt_array ($ch, [ CURLOPT_URL => 'https://appleid.apple.com/auth/token', CURLOPT_POSTFIELDS => http_build_query($data), CURLOPT_RETURNTRANSFER => true ]); $response = curl_exec($ch); curl_close ($ch); var_export(json_decode($response, true)); /** * array ( * 'access_token' => 'ab12cd3ef45db4f86a7d32cbbf7703a45.0.abcde.Ab01C3_D4elgkHOMcFuXpg', * 'token_type' => 'Bearer', * 'expires_in' => 3600, * 'refresh_token' => 'abcdef12345678bb9bbbefba3e36118a2.0.mrwxq.Vo5t5ogmUXFERuNtiMbrvg', * 'id_token' => 'RS256 Encoded Hash', * ) */