0

我能够通过启动范围/客户端 ID、重定向 URI 等将苹果登录注入网站

现在成功登录后,苹果使用发布响应将响应重定向到重定向 URI,请原谅我的无知!但是如何在我的网站上处理这个回调?我可以在 Apple 库本身中使用它吗?或者我需要建立自己的东西?当我在后端使用 RESTFul API 时,我期望获取令牌并将其传递给后端

我的页面是这样的

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
     <style>
        .signin-button {
            width: 210px;
            height: 40px;
        }
    </style>

        <meta name="appleid-signin-client-id" content="com.xxx.web">
        <meta name="appleid-signin-scope" content="name email">
        <meta name="appleid-signin-redirect-uri" content="https://xxx.xxx.com">
        <meta name="appleid-signin-state" content="authorized">
</head>
<body>

    <html>

    <body>

        <div id="appleid-signin" data-color="white" data-border="true" data-type="sign in"></div>

<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>

</script>
</body>
</html>

谢谢

4

1 回答 1

0

重定向 uri 对于苹果登录是强制性的,应该是一个有效的端点,例如

它接受 post 请求,Apple 将调用端点并在成功验证后传递代码id_token 。

下面是一个 PHP 控制器的示例

public function loginAppleAction(Request $request)
{
    $code = $request->request->get('code');
    $token = $request->request->get('id_token');

    // authorize the user in your system.
   // id_token is a JWT token that contains scope info like the email of the user. you can decode the JWT token using any JWT lib available.
  // make user login into your system.

}

appleid-signin-redirect-uri 中指定的主机必须包含域名。它不能是 IP 地址或本地主机。

在重定向 URI 的成功响应上,如果您需要执行其他任务,您还可以捕获 javascript 事件。

document.addEventListener('AppleIDSignInOnSuccess', function(data) {
         location.reload();    
});
于 2020-04-21T03:53:43.347 回答