提交 572a32af 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 d8f0f1a6
...@@ -19,6 +19,8 @@ Enumerates the window types of the authentication widget. ...@@ -19,6 +19,8 @@ Enumerates the window types of the authentication widget.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
| Name | Value | Description | | Name | Value | Description |
| ---------- | ---- | ---------- | | ---------- | ---- | ---------- |
| DIALOG_BOX | 1 | Dialog box.| | DIALOG_BOX | 1 | Dialog box.|
...@@ -30,35 +32,35 @@ Defines the user authentication parameters. ...@@ -30,35 +32,35 @@ Defines the user authentication parameters.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------- | ---------------------------------- | ---- | -------------------------------------- | | -------------- | ---------------------------------- | ---- | ------------------------------------------------------ |
| challenge | Uint8Array | Yes | Challenge value. The maximum length is 32 bytes. The value can be **null**.| | challenge | Uint8Array | Yes | Challenge value, which is used to prevent replay attacks. The challenge value can be null and cannot exceed 32 bytes.|
| authType | [UserAuthType](#userauthtype8)[] | Yes | Authentication type. | | authType | [UserAuthType](#userauthtype8)[] | Yes | Authentication type list, which specifies the authentications provided on the user authentication page.|
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Authentication trust level. | | authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | Yes | Authentication trust level. |
## WidgetParam<sup>10+</sup> ## WidgetParam<sup>10+</sup>
Defines the parameters of the authentication widget. Represents the information presented on the user authentication page.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------------------- | ----------------------------------- | ---- | -------------------- | | -------------------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
| title | string | Yes | Title of the authentication component. | | title | string | Yes | Title of the user authentication page. It cannot exceed 500 characters. |
| navigationButtonText | string | No | Description text of the navigation button.| | navigationButtonText | string | No | Text on the navigation button. It cannot exceed 60 characters. |
| windowModeType | [WindowModeType](#windowmodetype10) | No | Type of the window. | | windowMode | [WindowModeType](#windowmodetype10) | No | Display format of the user authentication page. The default value is **WindowModeType.DIALOG_BOX**.<br>**System API**: This is a system API.|
## UserAuthResult<sup>10+</sup> ## UserAuthResult<sup>10+</sup>
Defines the user authentication result. Defines the user authentication result. If the authentication is successful, the authentication type and information about the token that has passed the authentication are returned.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------ | ---- | ------------------------------------------------------------ |
| result | number | Yes | User authentication result. If the operation is successful, **0** is returned. If the operation fails, an error code is returned. For details about the error codes, see [User Authentication Error Codes](../errorcodes/errorcode-useriam.md).| | result | number | Yes | User authentication result. If the operation is successful, **0** is returned. If the operation fails, an error code is returned. For details about the error codes, see [User Authentication Error Codes](../errorcodes/errorcode-useriam.md).|
| token | Uint8Array | No | Authentication token information. | | token | Uint8Array | No | Token that has passed the authentication. |
| authType | [UserAuthType](#userauthtype8) | No | Authentication type. | | authType | [UserAuthType](#userauthtype8) | No | Type of the authentication. |
## IAuthCallback<sup>10+</sup> ## IAuthCallback<sup>10+</sup>
...@@ -75,51 +77,43 @@ Called to return the authentication result. ...@@ -75,51 +77,43 @@ Called to return the authentication result.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------------------------------- | ---- | ---------- | | ------ | ----------------------------------- | ---- | ---------- |
| result | [UserAuthResult](userauthresult10) | Yes | Authentication result.| | result | [UserAuthResult](#userauthresult10) | Yes | Authentication result.|
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
let userAuthInstance; };
try {
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success");
} catch (error) {
console.info("get userAuth instance failed, error = " + error);
}
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
userAuthInstance.on('result', { userAuthInstance.on('result', {
callback: onResult(result) { onResult (result) {
console.log("authV10 result " + result.result); console.log('userAuthInstance callback result = ' + JSON.stringify(result));
console.log("authV10 token " + result.token);
console.log("authV10 authType " + result.authType);
} }
}); });
console.info("subscribe authentication event success"); console.log('auth on success');
} catch (error) { } catch (error) {
console.info("subscribe authentication event failed" + error); console.log('auth catch error: ' + JSON.stringify(error));
//do error
} }
``` ```
## UserAuthInstance<sup>10+</sup> ## UserAuthInstance<sup>10+</sup>
Provides APIs for user authentication. The user authentication widget is supported. Provides APIs for user authentication. The user authentication widget is supported.
Before using the APIs, you need to obtain a **UserAuthInstance** instance by using [getUserAuthInstance](#useriam_userauthgetuserauthinstance10). Before using the APIs, you need to obtain a **UserAuthInstance** instance by using [getUserAuthInstance](#getuserauthinstance10).
### on<sup>10+</sup> ### on<sup>10+</sup>
...@@ -131,10 +125,10 @@ Subscribes to the user authentication result. ...@@ -131,10 +125,10 @@ Subscribes to the user authentication result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------------------ | | -------- | --------------------------------- | ---- | ------------------------------------------ |
| type | 'result' | Yes | Event type to subscribe to. **result** indicates the authentication result.| | type | 'result' | Yes | Event type to subscribe to. **result** indicates the authentication result.|
| callback | [IAuthCallback](iauthcallback10) | Yes | Callback invoked to return the user authentication result. | | callback | [IAuthCallback](#iauthcallback10) | Yes | Callback invoked to return the user authentication result. |
**Error codes** **Error codes**
...@@ -148,37 +142,29 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -148,37 +142,29 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
let userAuthInstance; };
try {
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success");
} catch (error) {
console.info("get userAuth instance failed, error = " + error);
}
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
userAuthInstance.on('result', { userAuthInstance.on('result', {
callback: onResult(result) { onResult (result) {
console.log("authV10 result " + result.result); console.log('userAuthInstance callback result = ' + JSON.stringify(result));
console.log("authV10 token " + result.token);
console.log("authV10 authType " + result.authType);
} }
}); });
console.info("subscribe authentication event success"); console.log('auth on success');
} catch (error) { } catch (error) {
console.info("subscribe authentication event failed" + error); console.log('auth catch error: ' + JSON.stringify(error));
//do error
} }
``` ```
...@@ -194,10 +180,10 @@ Unsubscribes from the user authentication result. ...@@ -194,10 +180,10 @@ Unsubscribes from the user authentication result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------------------ | | -------- | --------------------------------- | ---- | ------------------------------------------ |
| type | 'result' | Yes | Event type to unsubscribe from. **result** indicates the authentication result.| | type | 'result' | Yes | Event type to unsubscribe from. **result** indicates the authentication result.|
| callback | [IAuthCallback](iauthcallback10) | No | Callback for the user authentication result. | | callback | [IAuthCallback](#iauthcallback10) | No | Callback for the user authentication result. |
**Error codes** **Error codes**
...@@ -211,46 +197,29 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -211,46 +197,29 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
let userAuthInstance; };
try {
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success");
} catch (error) {
console.info("get userAuth instance failed, error = " + error);
}
// Subscribe to the authentication result.
try { try {
userAuthInstance.on('result', { let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
callback: onResult(result) { console.log('get userAuth instance success');
console.log("authV10 result " + result.result); userAuthInstance.off('result', {
console.log("authV10 token " + result.token); onResult (result) {
console.log("authV10 authType " + result.authType); console.log('auth off result: ' + JSON.stringify(result));
} }
}); });
console.info("subscribe authentication event success"); console.log('auth off success');
} catch (error) {
console.info("subscribe authentication event failed" + error);
//do error
}
// Unsubscribe from the authentication result.
try {
userAuthInstance.off('result');
console.info("cancel subscribe authentication event success");
} catch (error) { } catch (error) {
console.info("cancel subscribe authentication event failed" + error); console.log('auth catch error: ' + JSON.stringify(error));
//do error
} }
``` ```
...@@ -286,31 +255,25 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -286,31 +255,25 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
let userAuthInstance; };
try {
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success");
} catch (error) {
console.info("get userAuth instance failed, error = " + error);
}
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
userAuthInstance.start(); userAuthInstance.start();
console.info("userAuthInstanceV10 start auth success"); console.log('auth start success');
} catch (error) { } catch (error) {
console.info("userAuthInstanceV10 start auth failed, error = " + error); console.log('auth catch error: ' + JSON.stringify(error));
//do error
} }
``` ```
...@@ -337,46 +300,29 @@ Cancels this authentication. ...@@ -337,46 +300,29 @@ Cancels this authentication.
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
};
let userAuthInstance;
try {
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success");
} catch (error) {
console.info("get userAuth instance failed, error = " + error);
}
// Start user authentication.
try {
userAuthInstance.start();
console.info("userAuthInstanceV10 start auth success");
} catch (error) {
console.info("userAuthInstanceV10 start auth failed, error = " + error);
//do error
}
// Cancel the authentication.
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
userAuthInstance.cancel(); userAuthInstance.cancel();
console.info("cancel auth success"); console.log('auth cancel success');
} catch (error) { } catch (error) {
console.info("cancel auth failed, error = " + error); console.log('auth catch error: ' + JSON.stringify(error));
//do error
} }
``` ```
## userIAM_userAuth.getUserAuthInstance<sup>10+</sup> ## getUserAuthInstance<sup>10+</sup>
getUserAuthInstance(authParam: AuthParam, widgetParam: WidgetParam): UserAuthInstance getUserAuthInstance(authParam: AuthParam, widgetParam: WidgetParam): UserAuthInstance
...@@ -389,16 +335,16 @@ Obtains a [UserAuthInstance](#userauthinstance10) instance for user authenticati ...@@ -389,16 +335,16 @@ Obtains a [UserAuthInstance](#userauthinstance10) instance for user authenticati
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | ----------------------------- | ---- | -------------------------------------- | | ----------- | ----------------------------- | ---- | -------------------------- |
| authParam | [AuthParam](authparam10) | Yes | Challenge value. The maximum length is 32 bytes. The value can be **null**.| | authParam | [AuthParam](#authparam10) | Yes | User authentication parameters. |
| widgetParam | [WidgetParam](#widgetparam10) | Yes | Authentication type. Only **FACE** is supported. | | widgetParam | [WidgetParam](#widgetparam10) | Yes | Parameters on the user authentication page.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------------- | ------------ | | --------------------------------------- | -------------------------- |
| [UserAuthInstance](#userauthinstance10) | **UserAuthInstance** instance obtained.| | [UserAuthInstance](#userauthinstance10) | **UserAuthInstance** instance that supports UI.|
**Error codes** **Error codes**
...@@ -414,23 +360,23 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -414,23 +360,23 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
AuthParam authParam = { const authParam = {
challenge: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: userIAM_userAuth.UserAuthType.PIN; authType: [userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1; authTrustLevel: 10000,
} };
WidgetParam widgetParam = { const widgetParam = {
title: "Enter Password"; title:'Enter password',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX; navigationButtonText: 'Back',
} windowMode: userAuth.WindowModeType.DIALOG_BOX,
};
try { try {
let userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.info("get userAuth instance success"); console.log('get userAuth instance success');
} catch (error) { } catch (error) {
console.info("get userAuth instance failed, error = " + error); console.log('auth catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -440,11 +386,13 @@ Defines the type of the user authentication notification. ...@@ -440,11 +386,13 @@ Defines the type of the user authentication notification.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
| Name | Value | Description | | Name | Value | Description |
| ------------- | ---- | -------------------- | | ------------- | ---- | -------------------- |
| WIDGET_NOTICE | 1 | Notification from the user authentication widget.| | WIDGET_NOTICE | 1 | Notification from the user authentication widget.|
## userIAM_userAuth.sendNotice<sup>10+</sup> ## sendNotice<sup>10+</sup>
sendNotice(noticeType: NoticeType, eventData: string): void sendNotice(noticeType: NoticeType, eventData: string): void
...@@ -454,12 +402,14 @@ Sends a notification from the user authentication widget. ...@@ -454,12 +402,14 @@ Sends a notification from the user authentication widget.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ---------- | | ---------- | --------------------------- | ---- | ---------- |
| noticeType | [NoticeType](#noticetype) | Yes | Notification type.| | noticeType | [NoticeType](#noticetype10) | Yes | Notification type.|
| eventData | string | Yes | Event data.| | eventData | string | Yes | Event data.|
**Error codes** **Error codes**
...@@ -475,10 +425,24 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -475,10 +425,24 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
let noticeType = userIAM_userAuth.NoticeType.WIDGET_NOTICE; try {
sendNotice(noticeType, {"eventData" : "EVENT_AUTH_TYPE_READY"}); const eventData = {
widgetContextId: 123456,
event: 'EVENT_AUTH_TYPE_READY',
version: '1',
payload: {
type: ['pin']
},
};
const jsonEventData = JSON.stringify(eventData);
let noticeType = userAuth.NoticeType.WIDGET_NOTICE;
userAuth.sendNotice(noticeType, jsonEventData);
console.log('sendNotice success');
} catch (error) {
console.log('sendNotice catch error: ' + JSON.stringify(error));
}
``` ```
## UserAuthWidgetMgr<sup>10+</sup> ## UserAuthWidgetMgr<sup>10+</sup>
...@@ -493,6 +457,8 @@ Subscribes to commands from the user authentication framework. ...@@ -493,6 +457,8 @@ Subscribes to commands from the user authentication framework.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -512,26 +478,20 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -512,26 +478,20 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
let version = 1;
let userAuthWidgetMgr;
try {
userAuthWidgetMgr = userIAM_userAuth.getUserAuthWidgetMgr(version);
console.info("get userAuthWidgetMgr instance success");
} catch (error) {
console.info("get userAuthWidgetMgr instance failed, error = " + error);
}
const userAuthWidgetMgrVersion = 1;
try { try {
let userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(userAuthWidgetMgrVersion);
console.log('get userAuthWidgetMgr instance success');
userAuthWidgetMgr.on('command', { userAuthWidgetMgr.on('command', {
callback: sendCommand(cmdData) { sendCommand(cmdData) {
console.log("The cmdData is " + cmdData); console.log('The cmdData is ' + cmdData);
} }
}) })
console.info("subscribe authentication event success"); console.log('subscribe authentication event success');
} catch (error) { } catch (error) {
console.info("subscribe authentication event failed, error = " + error); console.log('userAuth widgetMgr catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -543,6 +503,8 @@ Unsubscribes from commands sent from the user authentication framework. ...@@ -543,6 +503,8 @@ Unsubscribes from commands sent from the user authentication framework.
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -562,38 +524,24 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -562,38 +524,24 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
let version = 1;
let userAuthWidgetMgr;
try {
userAuthWidgetMgr = userIAM_userAuth.getUserAuthWidgetMgr(version);
console.info("get userAuthWidgetMgr instance success");
} catch (error) {
console.info("get userAuthWidgetMgr instance failed, error = " + error);
}
// Subscribe to the commands sent from the user authentication framework. const userAuthWidgetMgrVersion = 1;
try { try {
userAuthWidgetMgr.on('command', { let userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(userAuthWidgetMgrVersion);
callback: sendCommand(cmdData) { console.log('get userAuthWidgetMgr instance success');
console.log("The cmdData is " + cmdData); userAuthWidgetMgr.off('command', {
sendCommand(cmdData) {
console.log('The cmdData is ' + cmdData);
} }
}) })
console.info("subscribe authentication event success"); console.log('cancel subscribe authentication event success');
} catch (error) { } catch (error) {
console.info("subscribe authentication event failed, error = " + error); console.log('userAuth widgetMgr catch error: ' + JSON.stringify(error));
}
// Unsubscribe from the commands sent from the user authentication framework.
try {
userAuthWidgetMgr.off('command');
console.info("cancel subscribe authentication event success");
} catch (error) {
console.info("cancel subscribe authentication event failed, error = " + error);
} }
``` ```
## userIAM_userAuth.getUserAuthWidgetMgr<sup>10+</sup> ## getUserAuthWidgetMgr<sup>10+</sup>
getUserAuthWidgetMgr(version: number): UserAuthWidgetMgr getUserAuthWidgetMgr(version: number): UserAuthWidgetMgr
...@@ -602,8 +550,12 @@ Obtains a **UserAuthWidgetMgr** instance for user authentication. ...@@ -602,8 +550,12 @@ Obtains a **UserAuthWidgetMgr** instance for user authentication.
> **NOTE**<br> > **NOTE**<br>
> A **UserAuthInstance** instance can be used for an authentication only once. > A **UserAuthInstance** instance can be used for an authentication only once.
**Required permissions**: ohos.permission.SUPPORT_USER_AUTH
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -630,14 +582,14 @@ For details about the error codes, see [User Authentication Error Codes](../erro ...@@ -630,14 +582,14 @@ For details about the error codes, see [User Authentication Error Codes](../erro
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
let version = 1; let userAuthWidgetMgrVersion = 1;
try { try {
let userAuthWidgetMgr = userIAM_userAuth.getUserAuthWidgetMgr(version); let userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(userAuthWidgetMgrVersion);
console.info("get userAuthWidgetMgr instance success"); console.log('get userAuthWidgetMgr instance success');
} catch (error) { } catch (error) {
console.info("get userAuthWidgetMgr instance failed, error = " + error); console.log('userAuth widgetMgr catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -653,6 +605,8 @@ Called to return the command sent from the user authentication framework to the ...@@ -653,6 +605,8 @@ Called to return the command sent from the user authentication framework to the
**System capability**: SystemCapability.UserIAM.UserAuth.Core **System capability**: SystemCapability.UserIAM.UserAuth.Core
**System API**: This is a system API.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -662,19 +616,20 @@ Called to return the command sent from the user authentication framework to the ...@@ -662,19 +616,20 @@ Called to return the command sent from the user authentication framework to the
**Example** **Example**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
let version = 1; const userAuthWidgetMgrVersion = 1;
try { try {
let userAuthWidgetMgr = userIAM_userAuth.getUserAuthWidgetMgr(version); let userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(userAuthWidgetMgrVersion);
console.log('get userAuthWidgetMgr instance success');
userAuthWidgetMgr.on('command', { userAuthWidgetMgr.on('command', {
callback: sendCommand(cmdData) { sendCommand(cmdData) {
console.log("The cmdData is " + cmdData); console.log('The cmdData is ' + cmdData);
} }
}) })
console.info("subscribe authentication event success"); console.log('subscribe authentication event success');
} catch (error) { } catch (error) {
console.info("subscribe authentication event failed, error = " + error); console.log('userAuth widgetMgr catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -1036,7 +991,7 @@ getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel ...@@ -1036,7 +991,7 @@ getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel
Obtains an **AuthInstance** instance for user authentication. Obtains an **AuthInstance** instance for user authentication.
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 9 and deprecated since API version 10. Use [getUserAuthInstance](#useriam_userauthgetuserauthinstance10) instead. > This API is supported since API version 9 and deprecated since API version 10. Use [getUserAuthInstance](#getuserauthinstance10) instead.
> **NOTE**<br> > **NOTE**<br>
> An **AuthInstance** instance can be used for an authentication only once. > An **AuthInstance** instance can be used for an authentication only once.
...@@ -1146,7 +1101,7 @@ Enumerates the authentication result codes. ...@@ -1146,7 +1101,7 @@ Enumerates the authentication result codes.
| BUSY | 12500007 | Indicates the busy state. | | BUSY | 12500007 | Indicates the busy state. |
| LOCKED | 12500009 | The authentication executor is locked. | | LOCKED | 12500009 | The authentication executor is locked. |
| NOT_ENROLLED | 12500010 | The user has not entered the authentication information.| | NOT_ENROLLED | 12500010 | The user has not entered the authentication information.|
| CANCELED_FROM_WIDGET | 12500011 | The authentication is canceled by the user from the user authentication widget. If this error code is returned, the authentication is customized by the application.| | CANCELED_FROM_WIDGET<sup>10+</sup> | 12500011 | The authentication is canceled by the user from the user authentication widget. If this error code is returned, the authentication is customized by the application.|
## UserAuth<sup>(deprecated)</sup> ## UserAuth<sup>(deprecated)</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册