Apple Sign in Javascript :: 如何处理成功的登录回调 (redirect_uri)



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

现在登录成功后,Apple 使用帖子响应将响应重定向到重定向 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>

谢谢

重定向 URI 对于 Apple 登录是必需的,并且应该是有效的端点,例如

接受 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();    
});

最新更新