Skip to content

Link the User’s Account

Follow these steps to link the user’s account.

  1. Add the following code after the <body> opening tag on your webpage. This code snippet facilitates the loading of the JavaScript SDK and establishes the 'amazon-root' tag for integration:

    <div id="amazon-root"></div> 
    <script type="text/javascript"> 
        window.onAmazonLoginReady = function() { 
            amazon.Login.setClientId('YOUR-CLIENT-ID'); 
        };
    
        (function(d) { 
            var a = d.createElement('script'); 
    
            a.type = 'text/javascript'; 
            a.async = true; 
            a.id = 'amazon-login-sdk'; 
            a.src = 'https://assets.loginwithamazon.com/sdk/eu/login1.js’; 
    
            d.getElementById('amazon-root').appendChild(a); 
        })(document); 
    </script>
    
  2. Replace YOUR-CLIENT-ID with the Client ID you receive when you obtain API keys.

  3. Add the following JavaScript after the Link Account button on your site to generate an AuthorizeRequest object:

    <script type="text/javascript"> 
        var params = "<Any additional parameter that you want to return back to identify the user>"; 
    
        document.getElementById('LoginWithAmazon').onclick = function() { 
            options = {scope:'payments::conduct_silentpay', response_type:'code',state : params, popup:false}; 
    
            amazon.Login.setAmazonDomain(amazon.Login.amazonDomain['in']); 
            amazon.Login.authorize(options,'YOURREDIRECT_URI'); 
    
            return false; 
        }; 
    </script> 
    
  4. Replace YOUR-REDIRECT_URI with the URL from the approved list.

  5. Optional: After user is authorized, provide the user an option to logout.

    <script type="text/javascript"> 
        document.getElementById('Logout').onclick = function() { 
            amazon.Login.logout(); 
        };  
    </script>