Options
All
  • Public
  • Public/Protected
  • All
Menu

aladin.js 1.0.1 Library Reference

Using the library

This reference describes the Aladin Javascript Software Developer Kit (SDK) reference. For complete Aladin documentation, see docs.aladin.org. There is also reference material available for both the iOS SDK and Android SDK.

Install the Library

$ npm install aladin

Quickstart: Build an application

  1. Install aladin.js with npm.

    npm install aladin --save
  2. Import Aladin into your project.

     import * as aladin from 'aladin'
  3. Wire up a sign in button.

     document.getElementById('signin-button').addEventListener('click', function() {
       aladin.redirectToSignIn()
     })
  4. Wire up a sign out button.

     document.getElementById('signout-button').addEventListener('click', function() {
       aladin.signUserOut(window.location.origin)
     })
  5. Include the logic to load user data and to handle the authentication response.

     function showProfile(profile) {
       var person = new aladin.Person(profile)
       document.getElementById('heading-name').innerHTML = person.name()
       document.getElementById('avatar-image').setAttribute('src', person.avatarUrl())
       document.getElementById('section-1').style.display = 'none'
       document.getElementById('section-2').style.display = 'block'
     }
    
     if (aladin.isUserSignedIn()) {
      const userData = aladin.loadUserData()
       showProfile(userData.profile)
     } else if (aladin.isSignInPending()) {
       aladin.handlePendingSignIn()
       .then(userData => {
         showProfile(userData.profile)
       })
     }
  6. Create a manifest.json file

     {
       "name": "Hello, Aladin",
       "start_url": "localhost:5000",
       "description": "A simple demo of Aladin Auth",
       "icons": [{
         "src": "https://helloaladin.com/icon-192x192.png",
         "sizes": "192x192",
         "type": "image/png"
       }]
     }

    Make sure your manifest.json file has appropriate CORS headers so that it can be fetched via an http GET from any origin.

  7. Serve your application

Add the library without a package manager

You can import aladin.js as a script without using a package manager. To securely use the latest distribution of aladin.js from a CDN, add the following script declaration in your application.

<script src="https://unpkg.com/blockstack@1.0.1/dist/blockstack.js" integrity="sha384-7icikTI7lxmv5Qn38XoUm9Quc2uZ0XNgS2BQYg8yUvQ3oikUc19j4dmxA0OW260l" crossorigin="anonymous"></script>

Generated using TypeDoc