-
Notifications
You must be signed in to change notification settings - Fork 2
AngularJS
The directive handles the role of 'browser, app' in this sequence diagram.
More info about the diagram can be found here:
linkID sdk / Authentication
An online demo can be found here. In this example, the client side is handled by this angularJS example, the back-end is a REST project in java. The project can be found on this github page
This angularJS directive requires 4 resources to work:
- First of all, AngularJS (duh), the lowest version on which it is tested is v1.2.9, the highest 1.5.0.
angular-resource- The linkIDQR directive js file
- The linkIDQR styling file
<head>
<link rel="stylesheet" href="//linkid.be/modules/angular/1-x/linkid-qr-1.0.0.css">
<head>
<body>
...
<script src="angular.js"></script>
<script src="angular-resource.js"></script>
<script src="//linkid.be/modules/angular/1-x/ng-linkid-qr-1.0.0.js"></script>Don't forget to add the linkIDQR module dependency to your app.js.
angular.module('app', ['ng-linkIDQR']);
The directive requires 3 arguments
- the first is the
initHrefwhich is aStringcontaining the REST url to start a new linkID authentication/payment and which returns a JSON object containing thesessionIdandqrCodeInforeturned by the linkID servers. - The
pollHrefis aStringcontaining the REST url to poll an existing linkID authentication/payment and returning its current state, the directive automatically adds a query parameter with thesessionIdreturned by theinitHrefcall. The query parameter is calledsessionId. The state should be a JSON object containing the fields of aLinkIDAuthPollResponseobject. - You can pass a
functionas argument to theonSuccesswhich will be executed upon a successful authentication/payment.
<div linkid-qr
init-href="${restPath}/linkid/start"
poll-href="${restPath}/linkid/poll"
on-success="loginSucceeded()"></div>other linkID authentication states:
-
onFailed|function| This function will be executed when the authentication/payment failed -
onExpired|function| This function will be executed when the authentication/payment expires(default 15min) -
onRetrieved|function| This function will be executed when the user has scanned the linkID QR-code and the session is retrieved -
onPayment|function| This function will be executed when the linkID payment is payed -
onPaymentFailed|function| This function will be executed when the linkID payment has failed
All of the authentication state functions have an optional parameter called state
eg. on-success="loginSucceeded(state)", in which the returned authentication/payment object is passed through. This could be useful for custom error messages if the authentication/payment failed. Using this object to pass other authentication/payment information is not recommended.
other optional attributes include:
-
displayDownloadButtons|boolean| displays download buttons for the linkID app -
initData|object| The object's fields and values will be appended to theinitHrefURL as a series of additional query parameters. This way you can give more context to your server when starting an authentication session. -
onQR|function| This function will be executed when the linkID QR-code is retrieved -
loadText|String| When the session is retrieved, this text will appear -
autoLoad|boolean| Start the linkID authentication/payment on pageLoad -
startQr|boolean| Use QR-code as authentication, even on mobile