O login com a Amazon diz que o usuário não consentiu, mas eles têm - Alexa SMAPI
Estou tentando recuperar uma lista de habilidades na minha conta de desenvolvedor Alexa usando a API de gerenciamento de habilidades (SMAPI).
Eu tenho o seguinte HTML / javascript:
<BODY>
<a href id="LoginWithAmazon">
<img border="0" alt="Login with Amazon" src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gry_312x64.png" width="156" height="32" />
</a>
<div id="amazon-root"></div>
<script type="text/javascript">
var client_id = "<client id>";
window.onAmazonLoginReady = function() {
amazon.Login.setClientId(client_id);
};
(function(d) {
var a = d.createElement('script'); a.type = 'text/javascript';
a.async = true; a.id = 'amazon-login-sdk';
a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
d.getElementById('amazon-root').appendChild(a);
})(document);
document.getElementById('LoginWithAmazon').onclick = function() {
options = {
scope : 'profile postal_code alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test',
interactive: 'always',
response_type: 'code'
};
amazon.Login.authorize(options, '<login page url>');
return false;
};
</script>
</BODY>
Que então chama a página de logon para obter o token de acesso apropriado:
$grant_type = 'authorization_code';
$client_id = $GLOBALS['client_id']; //your client id
$client_secret = $GLOBALS['client_secret']; //your client secret
$data = array(
"grant_type"=>"authorization_code",
"code" => $code,
"client_id"=> $client_id,
"client_secret"=> $client_secret
);
$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$ch = curl_init('https://api.amazon.com/auth/o2/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
$result = curl_exec($ch);
curl_close($ch);
$result_arr = json_decode($result, true);
if (isset($result_arr['error']) == true){ //there was an error obtaining the auth token
var_dump($result);
die('Error: There was an error authenticating with Amazon. Can you please start over again? Click <a href="index.php">here</a> to start again.');
}
return $result_arr;
Posso usar o access_token no $ result_arr para obter informações do perfil, mas quando o uso para obter uma lista de habilidades:
// exchange the access token for list of skills
$c = curl_init('https://api.amazonalexa.com/v0/skills/');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: ' . $access_token));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_POST, 1);
$r = curl_exec($c);
curl_close($c);
var_dump($r);
eu recebiO usuário não consentiu nesta operação
Eu devo estar perdendo algo básico aqui. Fiquei com a impressão de que o escopo na solicitação inicial:profile postal_code alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test
seria suficiente para dar acesso. Confirmei que a conta da Amazon mostra que o aplicativo tem acesso às permissões acima.