小编Han*_*shi的帖子

如何验证“通过Apple登录”中的代码?

我正在尝试验证我在重定向Uri上从“使用Apple登录”服务获得的代码。我使用了文档中的信息来创建发布数据并生成“ client_secret”。

我得到的回应是:{"error":"invalid_client"}

我的生成“ client_secret”的函数可以在下面找到:

function encode($data) {
    $encoded = strtr(base64_encode($data), '+/', '-_');
    return rtrim($encoded, '=');
}

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($payloads, $signature, $privKey, OPENSSL_ALGO_SHA256);
    if (!$success) return …
Run Code Online (Sandbox Code Playgroud)

php jwt apple-sign-in

13
推荐指数
1
解决办法
1893
查看次数

如何在Apple JS中使用“使用Apple登录”

我会通过Apple JS在网络上使用“使用Apple登录”。可以在以下位置找到代码示例:https : //developer.apple.com/documentation/signinwithapplejs/configuring_your_webpage_for_sign_in_with_apple

现在的问题是:什么是客户ID,在哪里可以找到它。我在https://developer.apple.com/account/resources/identifiers/list上测试了应用程序ID的标识符,并测试了服务ID的标识符。如果我单击按钮并在Mac上使用Touch ID进行验证,则会收到错误“ AUTH_ALERT_SIGN_UP_NOT_COMPLETED”:

在此处输入图片说明

这是使用的代码:

<html>
    <head>
    </head>
    <body>
        <button id="sign-in-with-apple-button"> Sign In with Apple </button>
        <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
        <script type="text/javascript">
            AppleID.auth.init({
                clientId : 'unknown',
                scope : 'email',
                redirectURI: 'https://mytld/test.php',
                state : 'DE'
            });

            const buttonElement = document.getElementById('sign-in-with-apple-button');
            buttonElement.addEventListener('click', () => {
                AppleID.auth.signIn();
            });
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我没有对test.php的请求。

html javascript apple-sign-in

7
推荐指数
1
解决办法
1985
查看次数

标签 统计

apple-sign-in ×2

html ×1

javascript ×1

jwt ×1

php ×1