我从https://stackoverflow.com/a/40920748/3925032引用,但在这里回答是因为问题并不完全相同。
您不需要 :jwt 在清单中。在您为 manage_app_url 设置的网站页面上,您将收听 jwt,因为正如您所指出的,它会附加到它上面。
*您也可以使用“oauth_final_destination”:“manage”,如果您希望它们在安装后最终出现在您的站点上。
{
"manifest": "1",
"version": "1.1.1",
"client_id" : "123456789101112",
"callback_url" : "https://www.your-domain.com/callback.php",
"scopes": ["read:site", "write:site"],
"manage_app_url": "https://www.your-domain.com/manage.php",
"oauth_final_destination" : "manage",
"locale": {
"default": "en-us",
"supported": ["en-us"]
},
"webhooks": {
"callback_url": "https://www.your-domain.com/webhooks.php",
"events": ["app.uninstall", "site.publish", "site.delete"]
},
"snippet": "files/assets/snippet.tpl"
}
在您网站的 manage_app_url 页面上,您将执行以下操作:
require('firebase/src/JWT.php');
use \Firebase\JWT\JWT;
if (isset($_GET['jwt'])) {
$app_client_id = "Your APP ID";
$client_secret = "Your APP SECRET";
$jtw = $_GET['jwt'];
/**
* You can add a leeway to account for when there is a clock skew times between
* the signing and verifying servers. It is recommended that this leeway should not be bigger than a few minutes.
* Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
*/
try {
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jtw, $client_secret, array('HS256'));
if (!empty($decoded)) {
$decoded_array = (array) $decoded;
// Continue with your websites code to verify the Weebly users info
// $decoded_array['user_id'];
// $decoded_array['site_id'];
// $decoded_array['iat'];
// $decoded_array['jti'];
// $decoded_array['callback_url'];
}
} //END TRY
catch (InvalidArgumentException $e) {
echo $e->getMessage();
}
catch (UnexpectedValueException $e) {
echo $e->getMessage();
}
catch (DomainException $e) {
echo $e->getMessage();
}
}// END IF ISSET JWT