I have been trying to integrate the Login with Amazon button into my website but have been continuously unsuccessful. I have been following AWS directions from this website : http://login.amazon.com/website . I have created a separate login.html file and handle_login.php file into the directory.
login.html :
<a href="#" id="LoginWithAmazon">
<img border="0" alt="Login with Amazon"
src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gold_156x32.png"
width="156" height="32" />
</a>
<script type="text/javascript">
document.getElementById('LoginWithAmazon').onclick = function() {
options = { scope : 'profile' };
amazon.Login.authorize(options, 'http://aws2.paperplane.io/handle_login.php');
return false;
};
</script>
<div id="amazon-root"></div>
<script type="text/javascript">
window.onAmazonLoginReady = function() {
amazon.Login.setClientId('amzn1.application-oa2-client.126f2098b3a74619a685a56af94196dc');
};
(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);
</script>
handle_login.php: // verify that the access token belongs to us $c = curl_init(' https://api.amazon.com/auth/o2/tokeninfo?access_token= ' . urlencode($_REQUEST['access_token'])); curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($c);
curl_close($c);
$d = json_decode($r);
if ($d->aud != 'amzn1.application-oa2- client.126f2098b3a74619a685a56af94196dc') {
// the access token does not belong to us
header('HTTP/1.1 404 Not Found');
echo 'Page not found';
exit;
}
// exchange the access token for user profile
$c = curl_init('https://api.amazon.com/user/profile');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: bearer ' . $_REQUEST['access_token']));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($c);
curl_close($c);
$d = json_decode($r);
echo sprintf('%s %s %s', $d->name, $d->email, $d->user_id);
Any help would be much appreciated!!
Paperplane.io doesn't support PHP files on their hosting:
I want to make something clear: Paperplane.io doesn't support any kind of server-side scripting language like PHP.
http://blog.paperplane.io/2013/09/18/using-wget-to-make-a-non-static-site-static.html
Because you're not stating what error you're getting or describing how it fails, there could be any of a number of things wrong. Here's a general debugging guide.
On Cloud9, both the HTML and the PHP/Apache/MySQL templates will serve .php pages, but only the PHP/Apache/MySQL template has cURL enabled . You need cURL for the back-end calls you make in the handle_login
page. Make sure you pick the right template.
When you're setting up your app in the app console, your URL for your pages will be something like https://[workspace name]-[your username].c9users.io/[filename]
. After you set up the name, description, and Privacy URL, you have to set up your web settings.
I know both fields say they're optional, but they're optional depending on how you're setting up your authorization flow.
You'll need to provide a valid origin here. That's not the exact page, but the root URL (ie https://www.amazon.com
is the root URL for many of Amazon's shopping pages).
You'll need to change the credential to your Client ID
in both of the files. Also, you have some spaces in the middle of the ID in what you pasted above, so that could be a problem.
Make sure the return URL actually points to your handle_login
on the same domain.
amazon.Login.authorize(options,'https://[workspace name]-[your username].c9users.io/handle_login.php');
If you ensure all of these are correct(ed), you should have no problem running the demo scripts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.