Coder Social home page Coder Social logo

nxlauth-js's Introduction

Installation

1. Import jQuery and NXLAuth-JS libs

This library requires jQuery to handle AJAX request to Auth provider

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdn.digitalme.my/js/1.1.0/nxlauth.min.js"></script>
$(document).ready(function () {
    // All javascript codes / functions should be inside jQuery `.ready()` block
});

2. Initialize NXLAuth-JS application

var nxlauth = new App({
    openIdConnectUrl: 'https://auth.digitalme.my',
    clientId: '<client-id>',
    redirectUri: '<redirect-uri>',
    scope: 'openid offline',
});
nxlauth.checkAuth(callback);

3. Login

nxlauth.login();

4. Get / Refresh Token

nxlauth.getToken(callback);

5. Get Userinfo

nxlauth.getUserInfo(accessToken, callback);

  • accessToken should be available in login / refresh token response
  • callback is your custom javascript callback function with 1 argument

Callback example

function callback(response) {
    var accessToken = response.accessToken;
    $('#access_token').val(accessToken);
}

Sample body of response as below:

{
  "accessToken": "N7jACtoS_eXdvauixngyggioRquqW86a8....2B978WQnAk9__CRznb6d6t5rEv-iY",
  "tokenType": "bearer",
  "expiresIn": 3599,
  "refreshToken": "LFn1YK8GMhgLtw4tUzU8gQJwrgcQFp3K....ULeFOA-j4WbCDleKLMqFRjGcn05PKvUue_-tktboMo",
  "scope": "openid offline",
  "idToken": "eyJhbGciOiJSUzI1NiIsImtp....dpm9FE8MTuurp4p_NDU",
  "issuedAt": 1546967672
}

Demo application

Demo application is a nodejs application built with express framework

1. Installation

$ cd example
$ npm install express --save

2. Running nodejs server

$ node server.js

3. Run test on browser

http://localhost:3000

Minify command

Use this tool to re-compile and minify the nxlauth.js into nxlauth.min.js

uglifyjs nxlauth.js -c -o nxlauth.min.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.