未验证 提交 c1eb6ec8 编写于 作者: O openharmony_ci 提交者: Gitee

!23803 【用户IAM】deprecated接口ArkTs整改

Merge pull request !23803 from liuziwei/master
...@@ -72,12 +72,12 @@ setSurfaceId(surfaceId: string): void; ...@@ -72,12 +72,12 @@ setSurfaceId(surfaceId: string): void;
import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; import userIAM_faceAuth from '@ohos.userIAM.faceAuth';
// 该surfaceId应该从XComponent控件获取,此处仅用作示例。 // 该surfaceId应该从XComponent控件获取,此处仅用作示例。
let surfaceId = "123456"; let surfaceId = '123456';
let manager = new userIAM_faceAuth.FaceAuthManager(); let manager = new userIAM_faceAuth.FaceAuthManager();
try { try {
manager.setSurfaceId(surfaceId); manager.setSurfaceId(surfaceId);
console.info("set surface id success"); console.info('set surface id success');
} catch (e) { } catch (e) {
console.error("set surface id failed, error = " + e); console.error('set surface id failed, error = ' + e);
} }
``` ```
...@@ -32,8 +32,8 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth'; ...@@ -32,8 +32,8 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
**系统能力**:SystemCapability.UserIAM.UserAuth.Core **系统能力**:SystemCapability.UserIAM.UserAuth.Core
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------- | ---- | ------------------------------------------------------ | | -------------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| challenge | Uint8Array | 是 | 挑战值,用来防重放攻击。最大长度为32字节,可以填null。 | | challenge | Uint8Array | 是 | 挑战值,用来防重放攻击。最大长度为32字节,可传Uint8Array([])。 |
| authType | [UserAuthType](#userauthtype8)[] | 是 | 认证类型列表,用来指定用户认证界面提供的认证方法。 | | authType | [UserAuthType](#userauthtype8)[] | 是 | 认证类型列表,用来指定用户认证界面提供的认证方法。 |
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 | | authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 |
...@@ -93,7 +93,6 @@ const authParam : userAuth.AuthParam = { ...@@ -93,7 +93,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -151,7 +150,6 @@ const authParam : userAuth.AuthParam = { ...@@ -151,7 +150,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -206,7 +204,6 @@ const authParam : userAuth.AuthParam = { ...@@ -206,7 +204,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -264,7 +261,6 @@ const authParam : userAuth.AuthParam = { ...@@ -264,7 +261,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -309,7 +305,6 @@ const authParam : userAuth.AuthParam = { ...@@ -309,7 +305,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -369,7 +364,6 @@ const authParam : userAuth.AuthParam = { ...@@ -369,7 +364,6 @@ const authParam : userAuth.AuthParam = {
const widgetParam :userAuth.WidgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -426,14 +420,14 @@ sendNotice(noticeType: NoticeType, eventData: string): void ...@@ -426,14 +420,14 @@ sendNotice(noticeType: NoticeType, eventData: string): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
class EventData { interface EventData {
widgetContextId: number = 0; widgetContextId: number;
event: string = ""; event: string;
version: string = ""; version: string;
payload: PayLoad = { type: ['pin'] }; payload: PayLoad;
} }
class PayLoad { interface PayLoad {
type:Object[] = []; type: Object[];
} }
try { try {
const eventData : EventData = { const eventData : EventData = {
...@@ -716,24 +710,24 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; ...@@ -716,24 +710,24 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
// 通过callback获取认证结果 // 通过callback获取认证结果
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
auth.on("result", { auth.on('result', {
callback: (result: userIAM_userAuth.AuthResultInfo) => { callback: (result: userIAM_userAuth.AuthResultInfo) => {
console.log("authV9 result " + result.result); console.log('authV9 result ' + result.result);
console.log("authV9 token " + result.token); console.log('authV9 token ' + result.token);
console.log("authV9 remainAttempts " + result.remainAttempts); console.log('authV9 remainAttempts ' + result.remainAttempts);
console.log("authV9 lockoutDuration " + result.lockoutDuration); console.log('authV9 lockoutDuration ' + result.lockoutDuration);
} }
} as userIAM_userAuth.AuthEvent); } as userIAM_userAuth.AuthEvent);
auth.start(); auth.start();
console.log("authV9 start success"); console.log('authV9 start success');
} catch (error) { } catch (error) {
console.log("authV9 error = " + error); console.log('authV9 error = ' + error);
// do error // do error
} }
// 通过callback获取认证过程中的提示信息 // 通过callback获取认证过程中的提示信息
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
auth.on("tip", { auth.on('tip', {
callback : (result : userIAM_userAuth.TipInfo) => { callback : (result : userIAM_userAuth.TipInfo) => {
switch (result.tip) { switch (result.tip) {
case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT: case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT:
...@@ -746,9 +740,9 @@ try { ...@@ -746,9 +740,9 @@ try {
} }
} as userIAM_userAuth.AuthEvent); } as userIAM_userAuth.AuthEvent);
auth.start(); auth.start();
console.log("authV9 start success"); console.log('authV9 start success');
} catch (error) { } catch (error) {
console.log("authV9 error = " + error); console.log('authV9 error = ' + error);
// do error // do error
} }
``` ```
...@@ -801,16 +795,16 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; ...@@ -801,16 +795,16 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
// 订阅认证结果 // 订阅认证结果
auth.on("result", { auth.on('result', {
callback: (result: userIAM_userAuth.AuthResultInfo) => { callback: (result: userIAM_userAuth.AuthResultInfo) => {
console.log("authV9 result " + result.result); console.log('authV9 result ' + result.result);
console.log("authV9 token " + result.token); console.log('authV9 token ' + result.token);
console.log("authV9 remainAttempts " + result.remainAttempts); console.log('authV9 remainAttempts ' + result.remainAttempts);
console.log("authV9 lockoutDuration " + result.lockoutDuration); console.log('authV9 lockoutDuration ' + result.lockoutDuration);
} }
}); });
// 订阅认证过程中的提示信息 // 订阅认证过程中的提示信息
auth.on("tip", { auth.on('tip', {
callback : (result : userIAM_userAuth.TipInfo) => { callback : (result : userIAM_userAuth.TipInfo) => {
switch (result.tip) { switch (result.tip) {
case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT: case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT:
...@@ -821,11 +815,11 @@ try { ...@@ -821,11 +815,11 @@ try {
// do others // do others
} }
} }
}); } as userIAM_userAuth.AuthEvent);
auth.start(); auth.start();
console.log("authV9 start success"); console.log('authV9 start success');
} catch (error) { } catch (error) {
console.log("authV9 error = " + error); console.log('authV9 error = ' + error);
// do error // do error
} }
``` ```
...@@ -865,34 +859,23 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth'; ...@@ -865,34 +859,23 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE; let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
let auth;
try {
auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
console.log("get auth instance success");
} catch (error) {
console.log("get auth instance failed" + error);
}
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
// 订阅认证结果 // 订阅认证结果
auth.on("result", { auth.on('result', {
callback: (result: userIAM_userAuth.AuthResultInfo) => { callback: (result: userIAM_userAuth.AuthResultInfo) => {
console.log("authV9 result " + result.result); console.log('authV9 result ' + result.result);
console.log("authV9 token " + result.token); console.log('authV9 token ' + result.token);
console.log("authV9 remainAttempts " + result.remainAttempts); console.log('authV9 remainAttempts ' + result.remainAttempts);
console.log("authV9 lockoutDuration " + result.lockoutDuration); console.log('authV9 lockoutDuration ' + result.lockoutDuration);
} }
}); });
console.log("subscribe authentication event success"); // 取消订阅结果
auth.off('result');
console.info('cancel subscribe authentication event success');
} catch (error) { } catch (error) {
console.log("subscribe authentication event failed " + error); console.info('cancel subscribe authentication event failed, error =' + error);
} // do error
// 取消订阅认证结果
try {
auth.off("result");
console.info("cancel subscribe authentication event success");
} catch (error) {
console.info("cancel subscribe authentication event failed, error = " + error);
} }
``` ```
...@@ -942,9 +925,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; ...@@ -942,9 +925,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
auth.start(); auth.start();
console.info("authV9 start auth success"); console.info('authV9 start auth success');
} catch (error) { } catch (error) {
console.info("authV9 start auth failed, error = " + error); console.info('authV9 start auth failed, error = ' + error);
} }
``` ```
...@@ -986,9 +969,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; ...@@ -986,9 +969,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
auth.cancel(); auth.cancel();
console.info("cancel auth success"); console.info('cancel auth success');
} catch (error) { } catch (error) {
console.info("cancel auth failed, error = " + error); console.info('cancel auth failed, error = ' + error);
} }
``` ```
...@@ -1010,7 +993,7 @@ getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel ...@@ -1010,7 +993,7 @@ getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | ------------------------ | | -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge | Uint8Array | 是 | 挑战值,最大长度为32字节,可以填null。 | | challenge | Uint8Array | 是 | 挑战值,最大长度为32字节,可以传Uint8Array([])。 |
| authType | [UserAuthType](#userauthtype8) | 是 | 认证类型,当前支持FACE。 | | authType | [UserAuthType](#userauthtype8) | 是 | 认证类型,当前支持FACE。 |
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 | | authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 |
...@@ -1042,9 +1025,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; ...@@ -1042,9 +1025,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try { try {
let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel); let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
console.info("get auth instance success"); console.info('let auth instance success');
} catch (error) { } catch (error) {
console.info("get auth instance success failed, error = " + error); console.info('get auth instance success failed, error = ' + error);
} }
``` ```
...@@ -1085,9 +1068,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth'; ...@@ -1085,9 +1068,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
try { try {
userIAM_userAuth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1); userIAM_userAuth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1);
console.info("current auth trust level is supported"); console.info('current auth trust level is supported');
} catch (error) { } catch (error) {
console.info("current auth trust level is not supported, error = " + error); console.info('current auth trust level is not supported, error = ' + error);
} }
``` ```
...@@ -1166,7 +1149,7 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth'; ...@@ -1166,7 +1149,7 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
let version = auth.getVersion(); let version = auth.getVersion();
console.info("auth version = " + version); console.info('auth version = ' + version);
``` ```
### getAvailableStatus<sup>(deprecated)</sup> ### getAvailableStatus<sup>(deprecated)</sup>
...@@ -1203,9 +1186,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth'; ...@@ -1203,9 +1186,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
let checkCode = auth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1); let checkCode = auth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1);
if (checkCode == userIAM_userAuth.ResultCode.SUCCESS) { if (checkCode == userIAM_userAuth.ResultCode.SUCCESS) {
console.info("check auth support success"); console.info('check auth support success');
} else { } else {
console.error("check auth support fail, code = " + checkCode); console.error('check auth support fail, code = ' + checkCode);
} }
``` ```
...@@ -1226,7 +1209,7 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev ...@@ -1226,7 +1209,7 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | ------------------------ | | -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge | Uint8Array | 是 | 挑战值,可以填null。 | | challenge | Uint8Array | 是 | 挑战值,可以传Uint8Array([])。 |
| authType | [UserAuthType](#userauthtype8) | 是 | 认证类型,当前支持FACE。 | | authType | [UserAuthType](#userauthtype8) | 是 | 认证类型,当前支持FACE。 |
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 | | authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是 | 认证信任等级。 |
| callback | [IUserAuthCallback](#iuserauthcallbackdeprecated) | 是 | 回调函数。 | | callback | [IUserAuthCallback](#iuserauthcallbackdeprecated) | 是 | 回调函数。 |
...@@ -1243,18 +1226,19 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev ...@@ -1243,18 +1226,19 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userIAM_userAuth from '@ohos.userIAM.userAuth';
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, { let challenge = new Uint8Array([]);
auth.auth(challenge, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, {
onResult: (result, extraInfo) => { onResult: (result, extraInfo) => {
try { try {
console.info("auth onResult result = " + result); console.info('auth onResult result = ' + result);
console.info("auth onResult extraInfo = " + JSON.stringify(extraInfo)); console.info('auth onResult extraInfo = ' + JSON.stringify(extraInfo));
if (result == userIAM_userAuth.ResultCode.SUCCESS) { if (result == userIAM_userAuth.ResultCode.SUCCESS) {
// 此处添加认证成功逻辑 // 此处添加认证成功逻辑
} else { } else {
// 此处添加认证失败逻辑 // 此处添加认证失败逻辑
} }
} catch (e) { } catch (e) {
console.info("auth onResult error = " + e); console.info('auth onResult error = ' + e);
} }
} }
}); });
...@@ -1295,9 +1279,9 @@ let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); ...@@ -1295,9 +1279,9 @@ let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
let cancelCode = auth.cancelAuth(contextId); let cancelCode = auth.cancelAuth(contextId);
if (cancelCode == userIAM_userAuth.ResultCode.SUCCESS) { if (cancelCode == userIAM_userAuth.ResultCode.SUCCESS) {
console.info("cancel auth success"); console.info('cancel auth success');
} else { } else {
console.error("cancel auth fail"); console.error('cancel auth fail');
} }
``` ```
...@@ -1332,18 +1316,19 @@ onResult: (result : number, extraInfo : AuthResult) => void ...@@ -1332,18 +1316,19 @@ onResult: (result : number, extraInfo : AuthResult) => void
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userIAM_userAuth from '@ohos.userIAM.userAuth';
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, { let challenge = new Uint8Array([]);
auth.auth(challenge, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, {
onResult: (result, extraInfo) => { onResult: (result, extraInfo) => {
try { try {
console.info("auth onResult result = " + result); console.info('auth onResult result = ' + result);
console.info("auth onResult extraInfo = " + JSON.stringify(extraInfo)); console.info('auth onResult extraInfo = ' + JSON.stringify(extraInfo));
if (result == userIAM_userAuth.ResultCode.SUCCESS) { if (result == userIAM_userAuth.ResultCode.SUCCESS) {
// 此处添加认证成功逻辑 // 此处添加认证成功逻辑
} else { } else {
// 此处添加认证失败逻辑 // 此处添加认证失败逻辑
} }
} catch (e) { } catch (e) {
console.info("auth onResult error = " + e); console.info('auth onResult error = ' + e);
} }
} }
}); });
...@@ -1374,14 +1359,28 @@ onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void ...@@ -1374,14 +1359,28 @@ onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userIAM_userAuth from '@ohos.userIAM.userAuth';
let auth = new userIAM_userAuth.UserAuth(); let auth = new userIAM_userAuth.UserAuth();
auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, { let challenge = new Uint8Array([]);
auth.auth(challenge, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, {
onResult: (result, extraInfo) => {
try {
console.info('auth onResult result = ' + result);
console.info('auth onResult extraInfo = ' + JSON.stringify(extraInfo));
if (result == userIAM_userAuth.ResultCode.SUCCESS) {
// 此处添加认证成功逻辑
} else {
// 此处添加认证失败逻辑
}
} catch (e) {
console.info('auth onResult error = ' + e);
}
},
onAcquireInfo: (module, acquire, extraInfo) => { onAcquireInfo: (module, acquire, extraInfo) => {
try { try {
console.info("auth onAcquireInfo module = " + module); console.info('auth onAcquireInfo module = ' + module);
console.info("auth onAcquireInfo acquire = " + acquire); console.info('auth onAcquireInfo acquire = ' + acquire);
console.info("auth onAcquireInfo extraInfo = " + JSON.stringify(extraInfo)); console.info('auth onAcquireInfo extraInfo = ' + JSON.stringify(extraInfo));
} catch (e) { } catch (e) {
console.info("auth onAcquireInfo error = " + e); console.info('auth onAcquireInfo error = ' + e);
} }
} }
}); });
...@@ -1506,6 +1505,8 @@ getAuthenticator(): Authenticator ...@@ -1506,6 +1505,8 @@ getAuthenticator(): Authenticator
**示例:** **示例:**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
let authenticator = userIAM_userAuth.getAuthenticator(); let authenticator = userIAM_userAuth.getAuthenticator();
``` ```
...@@ -1546,13 +1547,15 @@ callback返回值: ...@@ -1546,13 +1547,15 @@ callback返回值:
**示例:** **示例:**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
let authenticator = userIAM_userAuth.getAuthenticator(); let authenticator = userIAM_userAuth.getAuthenticator();
authenticator.execute("FACE_ONLY", "S2", (error, code)=>{ authenticator.execute('FACE_ONLY', 'S2', (error, code)=>{
if (code === userIAM_userAuth.ResultCode.SUCCESS) { if (code === userIAM_userAuth.ResultCode.SUCCESS) {
console.info("auth success"); console.info('auth success');
return; return;
} }
console.error("auth fail, code = " + code); console.error('auth fail, code = ' + code);
}); });
``` ```
...@@ -1586,11 +1589,13 @@ execute(type : AuthType, level : SecureLevel): Promise&lt;number&gt; ...@@ -1586,11 +1589,13 @@ execute(type : AuthType, level : SecureLevel): Promise&lt;number&gt;
**示例:** **示例:**
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
let authenticator = userIAM_userAuth.getAuthenticator(); let authenticator = userIAM_userAuth.getAuthenticator();
authenticator.execute("FACE_ONLY", "S2").then((code)=>{ authenticator.execute('FACE_ONLY', 'S2').then((code)=>{
console.info("auth success"); console.info('auth success');
}).catch((error)=>{ }).catch((error)=>{
console.error("auth fail, code = " + error); console.error('auth fail, code = ' + error);
}); });
``` ```
......
...@@ -48,9 +48,9 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证 ...@@ -48,9 +48,9 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
// 查询认证能力是否支持 // 查询认证能力是否支持
try { try {
userIAM_userAuth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1); userIAM_userAuth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1);
console.info("current auth trust level is supported"); console.info('current auth trust level is supported');
} catch (error) { } catch (error) {
console.info("current auth trust level is not supported, error = " + error); console.info('current auth trust level is not supported, error = ' + error);
} }
``` ```
...@@ -79,7 +79,6 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证 ...@@ -79,7 +79,6 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
const widgetParam : userIAM_userAuth.WidgetParam = { const widgetParam : userIAM_userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
//获取认证对象 //获取认证对象
...@@ -129,7 +128,6 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证 ...@@ -129,7 +128,6 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
const widgetParam : userIAM_userAuth.WidgetParam = { const widgetParam : userIAM_userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
//获取认证对象 //获取认证对象
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册