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
});
var nxlauth = new App({
openIdConnectUrl: 'https://auth.digitalme.my',
clientId: '<client-id>',
redirectUri: '<redirect-uri>',
scope: 'openid offline',
});
nxlauth.checkAuth(callback);
nxlauth.login();
nxlauth.getToken(callback);
nxlauth.getUserInfo(accessToken, callback);
accessToken
should be available in login / refresh token responsecallback
is your custom javascript callback function with 1 argument
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 is a nodejs application built with express framework
$ cd example
$ npm install express --save
$ node server.js
http://localhost:3000
Use this tool to re-compile and minify the nxlauth.js
into nxlauth.min.js
uglifyjs nxlauth.js -c -o nxlauth.min.js