Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8560f159
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8560f159
编写于
9月 04, 2023
作者:
L
liuziweicom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code
Signed-off-by:
N
liuziweicom
<
liuziwei12@huawei.com
>
上级
3de328fb
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
349 addition
and
347 deletion
+349
-347
zh-cn/application-dev/reference/apis/js-apis-useriam-faceauth.md
...pplication-dev/reference/apis/js-apis-useriam-faceauth.md
+4
-4
zh-cn/application-dev/reference/apis/js-apis-useriam-userauth.md
...pplication-dev/reference/apis/js-apis-useriam-userauth.md
+298
-284
zh-cn/application-dev/security/userauth-guidelines.md
zh-cn/application-dev/security/userauth-guidelines.md
+47
-59
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-useriam-faceauth.md
浏览文件 @
8560f159
...
...
@@ -72,12 +72,12 @@ setSurfaceId(surfaceId: string): void;
import
userIAM_faceAuth
from
'
@ohos.userIAM.faceAuth
'
;
// 该surfaceId应该从XComponent控件获取,此处仅用作示例。
let
surfaceId
=
"
123456
"
;
let
surfaceId
=
'
123456
'
;
let
manager
=
new
userIAM_faceAuth
.
FaceAuthManager
();
try
{
manager
.
setSurfaceId
(
surfaceId
);
console
.
info
(
"
set surface id success
"
);
console
.
info
(
'
set surface id success
'
);
}
catch
(
e
)
{
console
.
error
(
"
set surface id failed, error =
"
+
e
);
console
.
error
(
'
set surface id failed, error =
'
+
e
);
}
```
zh-cn/application-dev/reference/apis/js-apis-useriam-userauth.md
浏览文件 @
8560f159
...
...
@@ -32,8 +32,8 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
**系统能力**
:SystemCapability.UserIAM.UserAuth.Core
| 名称 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------- | ---- | ------------------------------------------------------ |
| challenge | Uint8Array | 是 | 挑战值,用来防重放攻击。最大长度为32字节,可
以填null
。 |
| -------------- | ---------------------------------- | ---- | ------------------------------------------------------
------
|
| challenge | Uint8Array | 是 | 挑战值,用来防重放攻击。最大长度为32字节,可
传Uint8Array([])
。 |
| authType |
[
UserAuthType
](
#userauthtype8
)[]
| 是 | 认证类型列表,用来指定用户认证界面提供的认证方法。 |
| authTrustLevel |
[
AuthTrustLevel
](
#authtrustlevel8
)
| 是 | 认证信任等级。 |
...
...
@@ -85,15 +85,14 @@ onResult(result: UserAuthResult): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -143,15 +142,14 @@ on(type: 'result', callback: IAuthCallback): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -198,15 +196,14 @@ off(type: 'result', callback?: IAuthCallback): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -256,15 +253,14 @@ start(): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -301,15 +297,14 @@ cancel(): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -361,15 +356,14 @@ getUserAuthInstance(authParam: AuthParam, widgetParam: WidgetParam): UserAuthIns
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
const
authParam
=
{
const
authParam
:
userAuth
.
AuthParam
=
{
challenge
:
new
Uint8Array
([
49
,
49
,
49
,
49
,
49
,
49
]),
authType
:
[
userAuth
.
UserAuthType
.
PIN
],
authTrustLevel
:
10000
,
authTrustLevel
:
userAuth
.
AuthTrustLevel
.
ATL1
,
};
const
widgetParam
=
{
const
widgetParam
:
userAuth
.
WidgetParam
=
{
title
:
'
请输入密码
'
,
navigationButtonText
:
'
返回
'
,
windowMode
:
userAuth
.
WindowModeType
.
DIALOG_BOX
,
};
try
{
let
userAuthInstance
=
userAuth
.
getUserAuthInstance
(
authParam
,
widgetParam
);
...
...
@@ -426,14 +420,23 @@ sendNotice(noticeType: NoticeType, eventData: string): void
```
js
import
userAuth
from
'
@ohos.userIAM.userAuth
'
;
interface
EventData
{
widgetContextId
:
number
;
event
:
string
;
version
:
string
;
payload
:
PayLoad
;
}
interface
PayLoad
{
type
:
Object
[];
}
try
{
const
e
ventData
=
{
const
eventData
:
E
ventData
=
{
widgetContextId
:
123456
,
event
:
'
EVENT_AUTH_TYPE_READY
'
,
version
:
'
1
'
,
payload
:
{
type
:
[
'
pin
'
]
}
,
}
as
PayLoad
,
};
const
jsonEventData
=
JSON
.
stringify
(
eventData
);
let
noticeType
=
userAuth
.
NoticeType
.
WIDGET_NOTICE
;
...
...
@@ -707,24 +710,24 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
// 通过callback获取认证结果
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
auth
.
on
(
"
result
"
,
{
auth
.
on
(
'
result
'
,
{
callback
:
(
result
:
userIAM_userAuth
.
AuthResultInfo
)
=>
{
console
.
log
(
"
authV9 result
"
+
result
.
result
);
console
.
log
(
"
authV9 token
"
+
result
.
token
);
console
.
log
(
"
authV9 remainAttempts
"
+
result
.
remainAttempts
);
console
.
log
(
"
authV9 lockoutDuration
"
+
result
.
lockoutDuration
);
console
.
log
(
'
authV9 result
'
+
result
.
result
);
console
.
log
(
'
authV9 token
'
+
result
.
token
);
console
.
log
(
'
authV9 remainAttempts
'
+
result
.
remainAttempts
);
console
.
log
(
'
authV9 lockoutDuration
'
+
result
.
lockoutDuration
);
}
}
);
}
as
userIAM_userAuth
.
AuthEvent
);
auth
.
start
();
console
.
log
(
"
authV9 start success
"
);
console
.
log
(
'
authV9 start success
'
);
}
catch
(
error
)
{
console
.
log
(
"
authV9 error =
"
+
error
);
console
.
log
(
'
authV9 error =
'
+
error
);
// do error
}
// 通过callback获取认证过程中的提示信息
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
auth
.
on
(
"
tip
"
,
{
auth
.
on
(
'
tip
'
,
{
callback
:
(
result
:
userIAM_userAuth
.
TipInfo
)
=>
{
switch
(
result
.
tip
)
{
case
userIAM_userAuth
.
FaceTips
.
FACE_AUTH_TIP_TOO_BRIGHT
:
...
...
@@ -735,11 +738,11 @@ try {
// do others
}
}
}
);
}
as
userIAM_userAuth
.
AuthEvent
);
auth
.
start
();
console
.
log
(
"
authV9 start success
"
);
console
.
log
(
'
authV9 start success
'
);
}
catch
(
error
)
{
console
.
log
(
"
authV9 error =
"
+
error
);
console
.
log
(
'
authV9 error =
'
+
error
);
// do error
}
```
...
...
@@ -792,16 +795,16 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
// 订阅认证结果
auth
.
on
(
"
result
"
,
{
auth
.
on
(
'
result
'
,
{
callback
:
(
result
:
userIAM_userAuth
.
AuthResultInfo
)
=>
{
console
.
log
(
"
authV9 result
"
+
result
.
result
);
console
.
log
(
"
authV9 token
"
+
result
.
token
);
console
.
log
(
"
authV9 remainAttempts
"
+
result
.
remainAttempts
);
console
.
log
(
"
authV9 lockoutDuration
"
+
result
.
lockoutDuration
);
console
.
log
(
'
authV9 result
'
+
result
.
result
);
console
.
log
(
'
authV9 token
'
+
result
.
token
);
console
.
log
(
'
authV9 remainAttempts
'
+
result
.
remainAttempts
);
console
.
log
(
'
authV9 lockoutDuration
'
+
result
.
lockoutDuration
);
}
});
// 订阅认证过程中的提示信息
auth
.
on
(
"
tip
"
,
{
auth
.
on
(
'
tip
'
,
{
callback
:
(
result
:
userIAM_userAuth
.
TipInfo
)
=>
{
switch
(
result
.
tip
)
{
case
userIAM_userAuth
.
FaceTips
.
FACE_AUTH_TIP_TOO_BRIGHT
:
...
...
@@ -812,11 +815,11 @@ try {
// do others
}
}
}
);
}
as
userIAM_userAuth
.
AuthEvent
);
auth
.
start
();
console
.
log
(
"
authV9 start success
"
);
console
.
log
(
'
authV9 start success
'
);
}
catch
(
error
)
{
console
.
log
(
"
authV9 error =
"
+
error
);
console
.
log
(
'
authV9 error =
'
+
error
);
// do error
}
```
...
...
@@ -856,34 +859,23 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let
challenge
=
new
Uint8Array
([
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
]);
let
authType
=
userIAM_userAuth
.
UserAuthType
.
FACE
;
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
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
// 订阅认证结果
auth
.
on
(
"
result
"
,
{
auth
.
on
(
'
result
'
,
{
callback
:
(
result
:
userIAM_userAuth
.
AuthResultInfo
)
=>
{
console
.
log
(
"
authV9 result
"
+
result
.
result
);
console
.
log
(
"
authV9 token
"
+
result
.
token
);
console
.
log
(
"
authV9 remainAttempts
"
+
result
.
remainAttempts
);
console
.
log
(
"
authV9 lockoutDuration
"
+
result
.
lockoutDuration
);
console
.
log
(
'
authV9 result
'
+
result
.
result
);
console
.
log
(
'
authV9 token
'
+
result
.
token
);
console
.
log
(
'
authV9 remainAttempts
'
+
result
.
remainAttempts
);
console
.
log
(
'
authV9 lockoutDuration
'
+
result
.
lockoutDuration
);
}
});
console
.
log
(
"
subscribe authentication event success
"
);
// 取消订阅结果
auth
.
off
(
'
result
'
);
console
.
info
(
'
cancel subscribe authentication event success
'
);
}
catch
(
error
)
{
console
.
log
(
"
subscribe authentication event failed
"
+
error
);
}
// 取消订阅认证结果
try
{
auth
.
off
(
"
result
"
);
console
.
info
(
"
cancel subscribe authentication event success
"
);
}
catch
(
error
)
{
console
.
info
(
"
cancel subscribe authentication event failed, error =
"
+
error
);
console
.
info
(
'
cancel subscribe authentication event failed, error =
'
+
error
);
// do error
}
```
...
...
@@ -933,9 +925,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
auth
.
start
();
console
.
info
(
"
authV9 start auth success
"
);
console
.
info
(
'
authV9 start auth success
'
);
}
catch
(
error
)
{
console
.
info
(
"
authV9 start auth failed, error =
"
+
error
);
console
.
info
(
'
authV9 start auth failed, error =
'
+
error
);
}
```
...
...
@@ -977,9 +969,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
auth
.
cancel
();
console
.
info
(
"
cancel auth success
"
);
console
.
info
(
'
cancel auth success
'
);
}
catch
(
error
)
{
console
.
info
(
"
cancel auth failed, error =
"
+
error
);
console
.
info
(
'
cancel auth failed, error =
'
+
error
);
}
```
...
...
@@ -1001,7 +993,7 @@ getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge | Uint8Array | 是 | 挑战值,最大长度为32字节,可以
填null。
|
| challenge | Uint8Array | 是 | 挑战值,最大长度为32字节,可以
传Uint8Array([])。
|
| authType |
[
UserAuthType
](
#userauthtype8
)
| 是 | 认证类型,当前支持FACE。 |
| authTrustLevel |
[
AuthTrustLevel
](
#authtrustlevel8
)
| 是 | 认证信任等级。 |
...
...
@@ -1033,9 +1025,9 @@ let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try
{
let
auth
=
userIAM_userAuth
.
getAuthInstance
(
challenge
,
authType
,
authTrustLevel
);
console
.
info
(
"
get auth instance success
"
);
console
.
info
(
'
let auth instance success
'
);
}
catch
(
error
)
{
console
.
info
(
"
get auth instance success failed, error =
"
+
error
);
console
.
info
(
'
get auth instance success failed, error =
'
+
error
);
}
```
...
...
@@ -1076,9 +1068,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
try
{
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
)
{
console
.
info
(
"
current auth trust level is not supported, error =
"
+
error
);
console
.
info
(
'
current auth trust level is not supported, error =
'
+
error
);
}
```
...
...
@@ -1157,7 +1149,7 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let
auth
=
new
userIAM_userAuth
.
UserAuth
();
let
version
=
auth
.
getVersion
();
console
.
info
(
"
auth version =
"
+
version
);
console
.
info
(
'
auth version =
'
+
version
);
```
### getAvailableStatus<sup>(deprecated)</sup>
...
...
@@ -1194,9 +1186,9 @@ import userIAM_userAuth from '@ohos.userIAM.userAuth';
let
auth
=
new
userIAM_userAuth
.
UserAuth
();
let
checkCode
=
auth
.
getAvailableStatus
(
userIAM_userAuth
.
UserAuthType
.
FACE
,
userIAM_userAuth
.
AuthTrustLevel
.
ATL1
);
if
(
checkCode
==
userIAM_userAuth
.
ResultCode
.
SUCCESS
)
{
console
.
info
(
"
check auth support success
"
);
console
.
info
(
'
check auth support success
'
);
}
else
{
console
.
error
(
"
check auth support fail, code =
"
+
checkCode
);
console
.
error
(
'
check auth support fail, code =
'
+
checkCode
);
}
```
...
...
@@ -1217,7 +1209,7 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge | Uint8Array | 是 | 挑战值,可以
填null。
|
| challenge | Uint8Array | 是 | 挑战值,可以
传Uint8Array([])。
|
| authType |
[
UserAuthType
](
#userauthtype8
)
| 是 | 认证类型,当前支持FACE。 |
| authTrustLevel |
[
AuthTrustLevel
](
#authtrustlevel8
)
| 是 | 认证信任等级。 |
| callback |
[
IUserAuthCallback
](
#iuserauthcallbackdeprecated
)
| 是 | 回调函数。 |
...
...
@@ -1234,18 +1226,19 @@ auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLev
import
userIAM_userAuth
from
'
@ohos.userIAM.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
));
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
);
console
.
info
(
'
auth onResult error =
'
+
e
);
}
}
});
...
...
@@ -1286,9 +1279,9 @@ let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
let
auth
=
new
userIAM_userAuth
.
UserAuth
();
let
cancelCode
=
auth
.
cancelAuth
(
contextId
);
if
(
cancelCode
==
userIAM_userAuth
.
ResultCode
.
SUCCESS
)
{
console
.
info
(
"
cancel auth success
"
);
console
.
info
(
'
cancel auth success
'
);
}
else
{
console
.
error
(
"
cancel auth fail
"
);
console
.
error
(
'
cancel auth fail
'
);
}
```
...
...
@@ -1323,18 +1316,19 @@ onResult: (result : number, extraInfo : AuthResult) => void
import
userIAM_userAuth
from
'
@ohos.userIAM.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
));
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
);
console
.
info
(
'
auth onResult error =
'
+
e
);
}
}
});
...
...
@@ -1365,14 +1359,28 @@ onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void
import
userIAM_userAuth
from
'
@ohos.userIAM.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
)
=>
{
try
{
console
.
info
(
"
auth onAcquireInfo module =
"
+
module
);
console
.
info
(
"
auth onAcquireInfo acquire =
"
+
acquire
);
console
.
info
(
"
auth onAcquireInfo extraInfo =
"
+
JSON
.
stringify
(
extraInfo
));
console
.
info
(
'
auth onAcquireInfo module =
'
+
module
);
console
.
info
(
'
auth onAcquireInfo acquire =
'
+
acquire
);
console
.
info
(
'
auth onAcquireInfo extraInfo =
'
+
JSON
.
stringify
(
extraInfo
));
}
catch
(
e
)
{
console
.
info
(
"
auth onAcquireInfo error =
"
+
e
);
console
.
info
(
'
auth onAcquireInfo error =
'
+
e
);
}
}
});
...
...
@@ -1497,6 +1505,8 @@ getAuthenticator(): Authenticator
**示例:**
```
js
import
userIAM_userAuth
from
'
@ohos.userIAM.userAuth
'
;
let
authenticator
=
userIAM_userAuth
.
getAuthenticator
();
```
...
...
@@ -1537,13 +1547,15 @@ callback返回值:
**示例:**
```
js
import
userIAM_userAuth
from
'
@ohos.userIAM.userAuth
'
;
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
)
{
console
.
info
(
"
auth success
"
);
console
.
info
(
'
auth success
'
);
return
;
}
console
.
error
(
"
auth fail, code =
"
+
code
);
console
.
error
(
'
auth fail, code =
'
+
code
);
});
```
...
...
@@ -1577,11 +1589,13 @@ execute(type : AuthType, level : SecureLevel): Promise<number>
**示例:**
```
js
import
userIAM_userAuth
from
'
@ohos.userIAM.userAuth
'
;
let
authenticator
=
userIAM_userAuth
.
getAuthenticator
();
authenticator
.
execute
(
"
FACE_ONLY
"
,
"
S2
"
).
then
((
code
)
=>
{
console
.
info
(
"
auth success
"
);
authenticator
.
execute
(
'
FACE_ONLY
'
,
'
S2
'
).
then
((
code
)
=>
{
console
.
info
(
'
auth success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
"
auth fail, code =
"
+
error
);
console
.
error
(
'
auth fail, code =
'
+
error
);
});
```
...
...
zh-cn/application-dev/security/userauth-guidelines.md
浏览文件 @
8560f159
...
...
@@ -33,6 +33,7 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
| ATL2 | FRR=10%时,FAR≤0.002%,7%<SAR≤20% | 能精确识别用户个体,有一定的活体检测能力,如基于普通测距和佩戴检测的手表作为可信持有物的认证。 | 维持设备解锁状态、应用登录 |
| ATL1 | FRR=10%时,FAR≤1%,7%<SAR≤20% | 能识别用户个体,有一定的活体检测能力,如声纹认证。 | 业务风控、一般个人数据查询、精准业务推荐、个性化服务 |
## 查询当前设备是否支持相应的认证能力
### 开发步骤
...
...
@@ -47,9 +48,9 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
// 查询认证能力是否支持
try {
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) {
console.info(
"current auth trust level is not supported, error = "
+ error);
console.info(
'current auth trust level is not supported, error = '
+ error);
}
```
...
...
@@ -70,20 +71,18 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
const authParam = {
const authParam
: userIAM_userAuth.AuthParam
= {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [
userAuth.UserAuthType.PIN],
authTrustLevel: 10000
,
authType: [userIAM_
userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1
,
};
const widgetParam = {
const widgetParam
: userIAM_userAuth.WidgetParam
= {
title: '请输入密码',
navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
};
let userAuthInstance;
try {
//获取认证对象
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
let
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
console.log('get userAuth instance success');
//订阅认证结果
userAuthInstance.on('result', {
...
...
@@ -94,11 +93,7 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
console.log('auth on success');
userAuthInstance.start();
console.log('auth start success');
} catch (error) {
console.log('auth on catch error: ' + JSON.stringify(error));
}
//取消订阅认证结果
try {
userAuthInstance.off('result', {
onResult (result) {
console.log('auth off result: ' + JSON.stringify(result));
...
...
@@ -125,30 +120,23 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括查询认证
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
const authParam = {
const authParam
: userIAM_userAuth.AuthParam
= {
challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
authType: [
userAuth.UserAuthType.PIN],
authTrustLevel: 10000
,
authType: [userIAM_
userAuth.UserAuthType.PIN],
authTrustLevel: userIAM_userAuth.AuthTrustLevel.ATL1
,
};
const widgetParam = {
const widgetParam
: userIAM_userAuth.WidgetParam
= {
title: '请输入密码',
navigationButtonText: '返回',
windowMode: userAuth.WindowModeType.DIALOG_BOX,
};
let userAuthInstance;
try {
//获取认证对象
userAuthInstance = userIAM_userAuth.getUserAuthInstance(authParam, widgetParam);
let
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 {
userAuthInstance.cancel();
console.log('auth cancel success');
} catch (error) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录