首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >登录苹果= invalid_client

登录苹果= invalid_client
EN

Stack Overflow用户
提问于 2019-10-17 00:21:29
回答 2查看 12.2K关注 0票数 10

我正面临着一个非常糟糕的问题,因为我读了那么多的指南和教程,什么也不管用。

结果总是一样的:{"error":"invalid_client"}

我得到了代码、identityToken和我需要的一切--除了调用https://appleid.apple.com/auth/token --是因为invalid_client。

这是我得到密码的网址。

https://appleid.apple.com/auth/authorize?response_type=code&client_id=org.example.service&redirect_uri=https%3A%2F%2Fexample.org

那么我就有了默认的工作流。在接受/退出后,我将被重定向到我的页面。

https://example.org/?code=a277243e2ec324fb09ba1c3333a8e6576.0.abcde.u4xiTDP2qHXoNEaxrcrIGx

(当我使用JavaScript API时,我将获得其他信息,如状态、代码和id_token。我已经用“代码”尝试过了。)

回到主要功能。

这是我对苹果的要求。

代码语言:javascript
运行
复制
'client_id' => 'org.example.service',  
'client_secret' => JWT-Data encoded (OPENSSL_ALGO_SHA256) see below  
'grant_type' => 'authorization_code',  
'code' => 'a277243e2ec324fb09ba1c3333a8e6576.0.abcde.u4xiTDP2qHXoNEaxrcrIGx'  

JWT头:

代码语言:javascript
运行
复制
{
  "alg": "ES256",
  "kid": "1ABC2345DE"
}  

JWT有效载荷:

代码语言:javascript
运行
复制
{
  "iss": "1A234BCD56",
  "iat": 1571269964,
  "exp": 1571273564,
  "aud": "https://appleid.apple.com",
  "sub": "org.example.service"
}

响应:

代码语言:javascript
运行
复制
{  
  "error": "invalid_client"  
}  

世界上无用的错误信息。

我不知道为什么客户应该是无效的。

我在https://developer.apple.com/account/resources/authkeys/list中有一个下载文件名为AuthKey_1ABC2345DE.p8的密钥。(意味着1ABC2345DE是我的关键id)

然后我有一个带有标识符"org.example“的本地iOS应用程序和一个带有标识符"org.example.service”的服务。

它不能同时处理ids和混合不同的东西。

没什么。invalid_client。

有人能帮我吗?我在这里坐了几个小时,只得到了invalid_client

我的测试页面:

代码语言:javascript
运行
复制
<html>
<head>
</head>
<body>
<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
<div id="appleid-signin" data-color="black" data-border="true" data-type="sign in" data-width="330px" data-height="100px"></div>
<script type="text/javascript">
    AppleID.auth.init({
        clientId : 'org.example.service',
        scope : 'email',
        redirectURI: 'https://example.org',
        state : 'EN'
    });
</script>
</body>
</html>

和PHP:

代码语言:javascript
运行
复制
<?php
// index.php

// function by https://stackoverflow.com/q/56459075/1362858
function encode($data) {
    $encoded = strtr(base64_encode($data), '+/', '-_');
    return rtrim($encoded, '=');
}

// function by https://stackoverflow.com/q/56459075/1362858
function generateJWT($kid, $iss, $sub, $key) {
    $header = [
        'alg' => 'ES256',
        'kid' => $kid
    ];
    $body = [
        'iss' => $iss,
        'iat' => time(),
        'exp' => time() + 3600,
        'aud' => 'https://appleid.apple.com',
        'sub' => $sub
    ];

    $privKey = openssl_pkey_get_private($key);
    if (!$privKey) return false;

    $payload = encode(json_encode($header)).'.'.encode(json_encode($body));
    $signature = '';
    $success = openssl_sign($payload, $signature, $privKey, OPENSSL_ALGO_SHA256);
    if (!$success) return false;

    return $payload.'.'.encode($signature);
}

$client_id = 'org.example.service';
$data = [
    'client_id' => $client_id,
    'client_secret' => generateJWT('1ABC2345DE', '1A234BCD56', $client_id, file_get_contents('AuthKey_1ABC2345DE.p8')),
    'code' => 'a277243e2ec324fb09ba1c3333a8e6576.0.abcde.u4xiTDP2qHXoNEaxrcrIGx',
    'grant_type' => 'authorization_code'
];
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://appleid.apple.com/auth/token');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$serverOutput = curl_exec($ch);

curl_close ($ch);

/**
 * {"error":"invalid_client"}
 */
var_dump($serverOutput);
EN

Stack Overflow用户

发布于 2021-10-08 19:10:17

嗯,我遇到了"invalid_client“这个错误,刚刚发现,https://developer.apple.com/account/resources/identifiers/serviceId中的所有凭据都被更改了。我认为,因为我们的法律实体(作为帐户持有人)的变化。所以,只要检查您的web应用程序ID和.p8键,它是否存在。

附注:有趣的是,大约一年前,我在这个问题中参与了这个问题,正如上面所描述的那样,它帮助了我(JWT ES256 algo)。现在,我希望,我能帮助别人找到另一个解决方案:-)

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58423244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档