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

!23699 用户IAM:ArkTs整改

Merge pull request !23699 from liuziwei/master
...@@ -85,15 +85,15 @@ onResult(result: UserAuthResult): void ...@@ -85,15 +85,15 @@ onResult(result: UserAuthResult): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -143,15 +143,15 @@ on(type: 'result', callback: IAuthCallback): void ...@@ -143,15 +143,15 @@ on(type: 'result', callback: IAuthCallback): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -198,15 +198,15 @@ off(type: 'result', callback?: IAuthCallback): void ...@@ -198,15 +198,15 @@ off(type: 'result', callback?: IAuthCallback): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -256,15 +256,15 @@ start(): void ...@@ -256,15 +256,15 @@ start(): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -301,15 +301,15 @@ cancel(): void ...@@ -301,15 +301,15 @@ cancel(): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -361,15 +361,15 @@ getUserAuthInstance(authParam: AuthParam, widgetParam: WidgetParam): UserAuthIns ...@@ -361,15 +361,15 @@ getUserAuthInstance(authParam: AuthParam, widgetParam: WidgetParam): UserAuthIns
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam :userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userAuth.WindowModeType.DIALOG_BOX,
}; };
try { try {
let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
...@@ -426,21 +426,30 @@ sendNotice(noticeType: NoticeType, eventData: string): void ...@@ -426,21 +426,30 @@ sendNotice(noticeType: NoticeType, eventData: string): void
```js ```js
import userAuth from '@ohos.userIAM.userAuth'; import userAuth from '@ohos.userIAM.userAuth';
class EventData {
widgetContextId: number = 0;
event: string = "";
version: string = "";
payload: PayLoad = { type: ['pin'] };
}
class PayLoad {
type:Object[] = [];
}
try { try {
const eventData = { const eventData : EventData = {
widgetContextId: 123456, widgetContextId: 123456,
event: 'EVENT_AUTH_TYPE_READY', event: 'EVENT_AUTH_TYPE_READY',
version: '1', version: '1',
payload: { payload: {
type: ['pin'] type: ['pin']
}, } as PayLoad,
}; };
const jsonEventData = JSON.stringify(eventData); const jsonEventData = JSON.stringify(eventData);
let noticeType = userAuth.NoticeType.WIDGET_NOTICE; let noticeType = userAuth.NoticeType.WIDGET_NOTICE;
userAuth.sendNotice(noticeType, jsonEventData); userAuth.sendNotice(noticeType, jsonEventData);
console.log('sendNotice success'); console.log('sendNotice success');
} catch (error) { } catch (error) {
console.log('sendNotice catch error: ' + JSON.stringify(error)); console.log('sendNotice catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -706,41 +715,41 @@ let authType = userIAM_userAuth.UserAuthType.FACE; ...@@ -706,41 +715,41 @@ let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1; 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);
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:
// do something; // do something;
case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_DARK: case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_DARK:
// do something; // do something;
default: default:
// 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
} }
``` ```
......
...@@ -71,43 +71,38 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证 ...@@ -71,43 +71,38 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userIAM_userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userIAM_userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userIAM_userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam : userIAM_userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX,
}; };
let userAuthInstance;
try { try {
//获取认证对象 //获取认证对象
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam); let userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success'); console.log('get userAuth instance success');
//订阅认证结果 //订阅认证结果
userAuthInstance.on('result', { userAuthInstance.on('result', {
onResult (result) { onResult (result) {
console.log('userAuthInstance callback result = ' + JSON.stringify(result)); console.log('userAuthInstance callback result = ' + JSON.stringify(result));
} }
}); });
console.log('auth on success'); console.log('auth on success');
userAuthInstance.start(); userAuthInstance.start();
console.log('auth start success'); console.log('auth start success');
//取消订阅认证结果
userAuthInstance.off('result', {
onResult (result) {
console.log('auth off result: ' + JSON.stringify(result));
}
});
console.log('auth off success');
} catch (error) { } catch (error) {
console.log('auth on catch error: ' + JSON.stringify(error)); console.log('auth catch error: ' + JSON.stringify(error));
}
//取消订阅认证结果
try {
userAuthInstance.off('result', {
onResult (result) {
console.log('auth off result: ' + JSON.stringify(result));
}
});
console.log('auth off success');
} catch (error) {
console.log('auth catch error: ' + JSON.stringify(error));
} }
``` ```
...@@ -126,33 +121,27 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证 ...@@ -126,33 +121,27 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
```js ```js
import userIAM_userAuth from '@ohos.userIAM.userAuth'; import userIAM_userAuth from '@ohos.userIAM.userAuth';
const authParam = { const authParam : userIAM_userAuth.AuthParam = {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [userAuth.UserAuthType.PIN], authType: [userIAM_userAuth.UserAuthType.PIN],
authTrustLevel: 10000, authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1,
}; };
const widgetParam = { const widgetParam : userIAM_userAuth.WidgetParam = {
title: '请输入密码', title: '请输入密码',
navigationButtonText: '返回', navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX, windowMode: userIAM_userAuth.WindowModeType.DIALOG_BOX,
}; };
let userAuthInstance;
try {
//获取认证对象
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
//开始认证
userAuthInstance.start();
console.log('auth start success');
} catch (error) {
console.log('auth catch error: ' + JSON.stringify(error));
}
// 取消认证
try { try {
userAuthInstance.cancel(); //获取认证对象
console.log('auth cancel success'); let userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
//开始认证
userAuthInstance.start();
console.log('auth start success');
// 取消认证
userAuthInstance.cancel();
console.log('auth cancel success');
} catch (error) { } catch (error) {
console.log('auth catch error: ' + JSON.stringify(error)); console.log('auth catch error: ' + JSON.stringify(error));
} }
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册