@acpaas-ui/js-eid-utils 中文文档教程
Eid module
EidMiddleware
Dios EidMiddleware 的 EidMiddleware 模块包装器
Example usage
在示例存储库中是一个关于如何使用 eid-middleware 的示例。
https://bitbucket.antwerpen.be/projects/AUI/repos/examples/browse/21eidmiddleware
## Initialize the middleware
该包将 eid.middleware
放在窗口对象上。
(function(eidMiddleware){
new eidMiddleware()
.initializeMiddleware()
.then(onStatusOk, onError);
})(window.eid.middleware)
initializeMiddleware()
此方法初始化必要的服务以与中间件通信。
返回:
Promise
。
onStatusOk
此回调接收一个 statusInfo
对象,如下所示:
{
code: 0,
app: {
url: '..',
version: '1.2.1'
}
}
code
属性包含从中间件返回的状态代码。
如果对象上有 app
属性,则表示您当前的版本已过期或未运行。
onError
当初始化未收到 OK
并收到如下所示的 statusInfo
对象时,将触发此回调:
{
code: 0,
app: {
url: '..',
version: '1.2.1'
}
}
code
属性包含状态码从中间件返回。
如果对象上有 app
属性,则表示您当前的版本已过期或未运行。
StatusCodes
所有状态代码都可以在 window.akit.services.eid.constants.statusCodes
中找到。 它们如下:
Value | Constant | Meaning |
---|---|---|
0 | OK | Everything is running and ready to communicate with. |
1 | SERVICENOTRUNNING | The middleware is not running. |
2 | INTERNALSERVICEERROR | An internal error occured while trying to connect to the middleware. |
3 | SERVICEOUTOF_DATE | The middleware is out of date, but running. |
4 | EXTENSIONNOTINSTALLED | The chrome extension is not installed. |
5 | NATIVEAPPNOT_INSTALLED | Java applet is not installed. |
6 | SANDBOXED | The middleware is running sandboxed. |
## Hooking up events
在 window.akit.services.eid
实例上有一个 onEvent
挂钩,您可以在其中监听所有事件。
window.akit.services.eid.onEvent('*', onCorrectCardInserted);
每个事件回调都有自己的签名,您可以在下表中找到。
Events
所有事件都可以在 window.akit.services.eid.events
上找到。 它们如下:
Value | Constant | Meaning | Callback signature |
---|---|---|---|
incorrectCardInserted | INCORRECTCARDINSERTED | The inserted card is incorrect. | fn(eventName) |
cardIncorrectInserted | CARDINCORRECTINSERTED | The card is incorrectly inserted. | fn(eventName) |
correctCardInserted | CORRECTCARDINSERTED | The card is correctly inserted. | fn(eventName, { eidCard , data}) |
correctCardRemoved | CORRECTCARDREMOVED | A correct card has been removed. | fn(eventName, { data }) |
incorrectInsertedCardRemoved | INCORRECTINSERTEDCARD_REMOVED | A incorrectly inserted card has been removed. | fn(eventName) |
incorrectCardRemoved | INCORRECTCARDREMOVED | An incorrect card has been removed. | fn(eventName) |
noCardReaderFound | NOCARDREADER_FOUND | The card reader was not found. | fn(eventName) |
cardReaderConnected | CARDREADERCONNECTED | A card reader connected. | fn(eventName, { name }) |
cardReaderDisconnected | CARDREADERDISCONNECTED | A cord reader disconnected. | fn(eventName, { name }) |
在所有这些事件旁边,您可以收听 *
,这表明您希望在所有 事件上收到通知。
## Working with the eID
在 CORRECT_CARD_INSERTED
事件中,您将获得 eIDInstance 作为参数。 该实例用于通过中间件与 eID 卡本身进行通信。
readValidationData()
此方法允许读取 eid_login 后端所需的所有验证数据。
eIdInstance
.readValidationData()
.then(function onSuccess(data){
}, function onError(error){
});
返回:
Promise
。 如果已解决,此承诺将具有以下对象。 所有日期都是 base64 编码的。
{
authenticationCertificate: ... ,
nonRepudiationCertificate: ... ,
rnCertificate: ... ,
rawAddressData: ... ,
addressDataSignature: ... ,
rawRnData: ... ,
rnDataSignature: ... ,
citizenCertificate: ...
}
如果承诺被拒绝,它将包含出错的错误。
signWithAuthenticationToken(token)
此方法使用提供的令牌创建经过签名的经过身份验证的签名。
eIdInstance
.signWithAuthenticationToken(token)
.then(function onSuccess(signedData){
}, function onError(error){
});
返回:
Promise
。 如果已解决,此承诺将具有签名数据。
如果承诺被拒绝,它将包含出错的错误。
setupPinRequestFlow
当中间件需要输入密码时,它有一个默认对话框(荷兰语)。 您可以使用 setupPinRequestflow
覆盖该对话框。
eIdInstance
.setupPinRequestFlow(
requestCallback,
onCorrectPin,
onError,
onTriesLeftUpdated
);
requestCallback
在此处构建您的对话逻辑。 使用 checkPin
要求中间件检查 pinCode。
...
requestCallback : function(checkPin, pinTriesLeft){
// show dialog
if(ok){
checkPin(enteredPinCode, null);
} else {
var error = {
message: 'user cancelled pin entry',
code: 2004
};
checkPin(null, error);
}
},
...
onCorrectPin
如果密码正确,将调用此回调。
...
onCorrectPin: function(){
// close dialog
},
...
onError
如果密码不正确,将调用此回调。
...
onError: function(error){
// Display the error
},
...
onTriesLeftUpdated
此回调将在尝试次数更改时调用。
...
onTriesLeftUpdated: function(tries){
// update ui with the remaining tries
}
Error codes
当使用 eIdInstance 和错误返回时,将返回以下对象结构:
{
message: '...',
code: 0000
}
下面列出了所有错误代码。
EIdInstance Error codes
Code | Meaning |
---|---|
2000 | No card in reader |
2001 | Communication error (with card). |
2002 | Parsing error: could not interpret date from the card. |
2003 | Timeout occurered (e.g. pin code entry). |
2004 | Operation cancelled by the user (e.g. with entry of the pin code). |
2005 | Operation aborded (e.g. removing card while entering pin code). |
2100 | Wrong pin, 2 tries left. |
2101 | Wrong pin, 1 try left. |
2102 | Wrong pin, card blocked. |
Eid module
EidMiddleware
EidMiddleware module wrapper for Dios EidMiddleware
Example usage
In the example repository is an example on how to use eid-middleware.
https://bitbucket.antwerpen.be/projects/AUI/repos/examples/browse/21eidmiddleware
## Initialize the middleware
The package puts an eid.middleware
on the window object.
(function(eidMiddleware){
new eidMiddleware()
.initializeMiddleware()
.then(onStatusOk, onError);
})(window.eid.middleware)
initializeMiddleware()
This method initializes the necessary services to communicate with the middleware.
Returns:
A Promise
.
onStatusOk
This callback receives a statusInfo
object which looks like this:
{
code: 0,
app: {
url: '..',
version: '1.2.1'
}
}
The code
property contains the statuscode returned from the middleware.
If app
property is on the object it means that your current version is out of date or not running.
onError
This callback is triggered when the initialisation didn't recieve an OK
and receives a statusInfo
object which looks like this:
{
code: 0,
app: {
url: '..',
version: '1.2.1'
}
}
The code
property contains the statuscode returned from the middleware.
If app
property is on the object it means that your current version is out of date or not running.
StatusCodes
All status code can be found on window.akit.services.eid.constants.statusCodes
. They are the following:
Value | Constant | Meaning |
---|---|---|
0 | OK | Everything is running and ready to communicate with. |
1 | SERVICENOTRUNNING | The middleware is not running. |
2 | INTERNALSERVICEERROR | An internal error occured while trying to connect to the middleware. |
3 | SERVICEOUTOF_DATE | The middleware is out of date, but running. |
4 | EXTENSIONNOTINSTALLED | The chrome extension is not installed. |
5 | NATIVEAPPNOT_INSTALLED | Java applet is not installed. |
6 | SANDBOXED | The middleware is running sandboxed. |
## Hooking up events
On the window.akit.services.eid
instance there is an onEvent
hook where you can listen voor all the events.
window.akit.services.eid.onEvent('*', onCorrectCardInserted);
Each event callback has his own signature, which you can find in the table below.
Events
All event can be found on window.akit.services.eid.events
. They are the following:
Value | Constant | Meaning | Callback signature |
---|---|---|---|
incorrectCardInserted | INCORRECTCARDINSERTED | The inserted card is incorrect. | fn(eventName) |
cardIncorrectInserted | CARDINCORRECTINSERTED | The card is incorrectly inserted. | fn(eventName) |
correctCardInserted | CORRECTCARDINSERTED | The card is correctly inserted. | fn(eventName, { eidCard , data}) |
correctCardRemoved | CORRECTCARDREMOVED | A correct card has been removed. | fn(eventName, { data }) |
incorrectInsertedCardRemoved | INCORRECTINSERTEDCARD_REMOVED | A incorrectly inserted card has been removed. | fn(eventName) |
incorrectCardRemoved | INCORRECTCARDREMOVED | An incorrect card has been removed. | fn(eventName) |
noCardReaderFound | NOCARDREADER_FOUND | The card reader was not found. | fn(eventName) |
cardReaderConnected | CARDREADERCONNECTED | A card reader connected. | fn(eventName, { name }) |
cardReaderDisconnected | CARDREADERDISCONNECTED | A cord reader disconnected. | fn(eventName, { name }) |
Next to all these events you can listen for *
which indicate that you want to be notified on all events.
## Working with the eID
On the CORRECT_CARD_INSERTED
event you get and eIDInstance as parameter. This instance is used to communicate with the eID card itself through the middleware.
readValidationData()
This method allows the reading of all validation data required by eid_login backend.
eIdInstance
.readValidationData()
.then(function onSuccess(data){
}, function onError(error){
});
Returns:
A Promise
. This promise has the following object if resolved. All the date is base64 encoded.
{
authenticationCertificate: ... ,
nonRepudiationCertificate: ... ,
rnCertificate: ... ,
rawAddressData: ... ,
addressDataSignature: ... ,
rawRnData: ... ,
rnDataSignature: ... ,
citizenCertificate: ...
}
If the promise is rejected it will contain the error where things went wrong.
signWithAuthenticationToken(token)
This method creates a signed authenticated signature with the provided token.
eIdInstance
.signWithAuthenticationToken(token)
.then(function onSuccess(signedData){
}, function onError(error){
});
Returns:
A Promise
. This promise has the signed data if resolved.
If the promise is rejected it will contain the error where things went wrong.
setupPinRequestFlow
When the middleware requires the insertion of the pincode, it has a default dialog (in dutch). You can use setupPinRequestflow
to overwrite that dialog.
eIdInstance
.setupPinRequestFlow(
requestCallback,
onCorrectPin,
onError,
onTriesLeftUpdated
);
requestCallback
Construct your dialog logic here. Use checkPin
to ask the middleware to check the pinCode.
...
requestCallback : function(checkPin, pinTriesLeft){
// show dialog
if(ok){
checkPin(enteredPinCode, null);
} else {
var error = {
message: 'user cancelled pin entry',
code: 2004
};
checkPin(null, error);
}
},
...
onCorrectPin
This callback will be called if the pincode was correct.
...
onCorrectPin: function(){
// close dialog
},
...
onError
This callback will be called if the pincode was incorrect.
...
onError: function(error){
// Display the error
},
...
onTriesLeftUpdated
This callback will be called when the amount of tries changed.
...
onTriesLeftUpdated: function(tries){
// update ui with the remaining tries
}
Error codes
When working with the eIdInstance and errors return the following object structure will be returned:
{
message: '...',
code: 0000
}
All error codes are listed below.
EIdInstance Error codes
Code | Meaning |
---|---|
2000 | No card in reader |
2001 | Communication error (with card). |
2002 | Parsing error: could not interpret date from the card. |
2003 | Timeout occurered (e.g. pin code entry). |
2004 | Operation cancelled by the user (e.g. with entry of the pin code). |
2005 | Operation aborded (e.g. removing card while entering pin code). |
2100 | Wrong pin, 2 tries left. |
2101 | Wrong pin, 1 try left. |
2102 | Wrong pin, card blocked. |