6.11.0-300 • Published 2 years ago
@hw-hmscore/hms-jsb-account v6.11.0-300
概述
帐号开发鸿蒙 HMS Core 适配 JavaScript API
类定义
| Class | Description | Status | 
|---|---|---|
| HuaweiIdAuthManager | 帐号对外接口统一门面类 | Open | 
| HuaweiIdAuth | 帐号登录退出取消授权接口实现类,不对外暴露,使用 HuaweiIdAuthManager 获取接口 | Close | 
| Scope | 帐号授权范围类,预置常用范围对象 EMAIL, OPENID, PROFILE, SHIPPING_ADDRESS | Open | 
| Permission | 帐号权限类,预置常用权限 UID_DYNAMIC_PERMISSION | Open | 
| HuaweiIdAuthParamsHelper | 帐号登录参数建造者类 | Open | 
| HuaweiIdAuthParams | 帐号登录参数类,不对外暴露,请使用 HuaweiIdAuthParamsHelper 构造 | Close | 
| HuaweiIdGetTokenOptions | 帐号静默登录获取IdToken 参数 | Open | 
| ForegroundManager | 帐号对外开放页面统一门面类 | Open | 
| ForegroundApi | 帐号对外开放实现类,不对外暴露,使用 ForegroundManager 获取接口 | Open | 
HuaweiIdAuthManager
account 对外 JavaScript API 门面类
Kind: global constant
- HuaweiIdAuthManager
- getAuthApi
 - addAuthScopes(scopeList)
 - containScopes(authId, scopeList)
 - getAuthResultWithScopes(scopeList)
 - getAuthResult
 
 
HuaweiIdAuthManager.getAuthApi()
返回帐号登录,静默登录,退出,取消授权接口
函数入参: 无
函数返回值:
| Type | Description | 
|---|---|
| HuaweiIdAuth | 帐号登录,静默登录,退出,取消授权接口实现对象 | 
示例代码:
import { HuaweiIdAuthManager} from 'hms-jsb-account'
var authApi =  HuaweiIdAuthManager.getAuthApi();HuaweiIdAuthManager.addScopes(scopeList)
新增授权范围 Scope 列表并且后台静默登录
函数入参:
| Param | Type | Description | 
|---|---|---|
| scopeList | Array | 授权范围 Scope 列表 | 
函数返回值: 无
示例代码:
import { HuaweiIdAuthManager, PROFILE} from 'hms-jsb-account'
var scopeList = new Array();
scopeList.push(PROFILE);
HuaweiIdAuthManager.addAuthScopes(scopeList);HuaweiIdAuthManager.containScopes(authId, scopeList)
判断登录成功后返回帐号信息是否包含指定授权范围 Scope 列表
函数入参:
| Param | Type | Description | 
|---|---|---|
| authId | AuthHuaweiId Object | 登录成功后返回的华为帐号信息 | 
函数返回值:
| Type | Description | 
|---|---|
| Boolean | true: 帐号信息包含授权范围列表 false: 帐号信息不包含授权范围列表 | 
示例代码:
import { HuaweiIdAuthManager, OPENID, PROFILE} from 'hms-jsb-account'
var scopeList = new Array();
scopeList.push(OPENID);
scopeList.push(PROFILE);
var isContained = HuaweiIdAuthManager.containScopes(null, scopeList);HuaweiIdAuthManager.getAuthResultWithScopes(scopeList)
登录成功后返回的帐号信息中添加指定授权范围 Scope 列表
函数入参:
| Param | Type | Description | 
|---|---|---|
| scopeList | Array | 授权范围 Scope 列表 | 
函数返回值:
| Type | Description | 
|---|---|
| AuthHuaweiId | 返回增加了授权范围列表的登录成功帐号信息 | 
示例代码:
import { HuaweiIdAuthManager, GAMES} from 'hms-jsb-account'
var scopeList = new Array();
scopeList.push(GAMES);
var authId = HuaweiIdAuthManager.getAuthResultWithScopes(scopeList);HuaweiIdAuthManager.getAuthResult()
返回登录成功后缓存中的帐号信息
Kind: method method of HuaweiIdAuthManager
函数入参: 无
函数返回值:
| Type | Description | 
|---|---|
| Promise | 返回包含缓存中登录成功帐号信息的异步回调 | 
示例代码:
import { HuaweiIdAuthManager} from 'hms-jsb-account'
HuaweiIdAuthManager.getAuthResult().then((result) => {
	console.info("getAuthResult success");
	console.info(JSON.stringify(result));
    this.getAuthResult = "getAuthResult success: " + JSON.stringify(result);
}).catch((error) => {
	console.info("getAuthResult fail:" + error);
    this.getAuthResult = "getAuthResult fail: " + error;
});HuaweiIdAuth
account 对外导出登录,静默登录,退出,授权 JS API。推荐使用 HuaweiIdAuthManager.getAuthApi() 获取接口对象。然后调用相关接口。
Kind: global constant
- HuaweiIdAuth
- getSignIntent(signInOption)
 - silentSignIn()
 - signOut()
 - cancelAuthorization()
 
 
HuaweiIdAuth.getSignIntent(signInOption)
前台帐号登录
函数入参:
| type | description | 
|---|---|
| HuaweiIdAuthParams | 鉴权参数对象,该对象一般不直接构造,而是使用 HuaweiIdAuthParamsHelper 通过构造者模式创建 | 
函数返回值:
| Type | Description | 
|---|---|
| Promise | 返回包含缓存中登录成功帐号信息的异步回调 | 
示例代码:
import { HuaweiIdAuthParamsHelper, HuaweiIdAuthManager } from 'hms-jsb-account'
var signInOption = new HuaweiIdAuthParamsHelper().setId().setProfile().setAuthorizationCode().build();
console.info(JSON.stringify(signInOption));
HuaweiIdAuthManager.getAuthApi().getSignInIntent(signInOption).then((result)=>{
	console.info("signIn success");
	console.info(JSON.stringify(result));
	this.signInResult = "signIn success: " + JSON.stringify(result);
}).catch((error)=>{
	console.error("signIn fail");
	console.error(JSON.stringify(error));
	this.signInResult = "signIn fail: " + JSON.stringify(error);
});HuaweiIdAuth.silentSignIn()
后台帐号静默登录
函数入参: 可接收一个参数或者两个参数
| Type | Description | OptiOn | 
|---|---|---|
| HuaweiIdAuthParams | 鉴权参数对象,该对象一般不直接构造,而是使用 HuaweiIdAuthParamsHelper 通过构造者模式创建 | 必选 | 
| HuaweiIdGetTokenOptions | 如果用户希望获取 IdToken, 需要传入此参数 | 可选 | 
函数返回值:
| Type | Description | 
|---|---|
| Promise | 返回包含缓存中登录成功帐号信息的异步回调 | 
示例代码:
import { HuaweiIdAuthParamsHelper, HuaweiIdAuthManager, OPENID, PROFILE, HuaweiIdGetTokenOptions} from 'hms-jsb-account'
 
// case 1: one paramter
var signInOption = new HuaweiIdAuthParamsHelper().setId().setProfile().setIdToken().build();
console.error(JSON.stringify(signInOption));
HuaweiIdAuthManager.getAuthApi().silentSignIn(signInOption).then((result)=>{
	console.info("signIn success");
	console.info(JSON.stringify(result));
	this.signInResult = "signIn success: " + JSON.stringify(result);
}).catch((error)=>{
	console.error("signIn fail");
	console.error(JSON.stringify(error));
	this.signInResult = "signIn fail: " + JSON.stringify(error);
});
// case 2: two paramters
var signInOption = new HuaweiIdAuthParamsHelper().setId().setProfile().setIdToken().build();
console.error(JSON.stringify(signInOption));
// current login account name
var curAccountName = "xxxxxx";
var idTokenOption = new HuaweiIdGetTokenOptions(curAccountName, true);
HuaweiIdAuthManager.getAuthApi().silentSignIn(signInOption, idTokenOption).then((result)=>{
	console.info("signIn success");
	console.info(JSON.stringify(result));
	this.signInResult = "signIn success: " + JSON.stringify(result);
}).catch((error)=>{
	console.error("signIn fail");
	console.error(JSON.stringify(error));
	this.signInResult = "signIn fail: " + JSON.stringify(error);
});HuaweiIdAuth.signOut()
帐号退出
函数入参: 无
函数返回值:
| Type | Description | 
|---|---|
| Promise<> | 返回帐号登场异步回调 | 
示例代码:
import { HuaweiIdAuthManager} from 'hms-jsb-account'
HuaweiIdAuthManager.getAuthApi().signOut().then((result)=>{
	console.info("signOut success");
	console.info(JSON.stringify(result));
	this.signOutResult = "signOut success: " + JSON.stringify(result);
}).catch((error) => {
	console.error("signout fail");
	console.error(JSON.stringify(error));
 	this.signOutResult = "signOut fail: " + JSON.stringify(error);
});HuaweiIdAuth.cancelAuthorization()
帐号取消授权
函数入参: 无
函数返回值:
| Type | Description | 
|---|---|
| Promise<> | 返回帐号取消授权异步回调 | 
示例代码:
import { HuaweiIdAuthManager} from 'hms-jsb-account'
var signInOption = new HuaweiIdAuthParamsHelper().setId().setProfile().setAuthorizationCode().build();
console.error(JSON.stringify(signInOption));
HuaweiIdAuthManager.getAuthApi().cancelAuthorization(signInOption).then((result)=>{
	console.info("cancelAuthorization success");
	console.info(JSON.stringify(result));
	this.revokeAccessResult = "cancelAuthorization success: " + JSON.stringify(result);
}).catch((error) => {
	console.error("cancelAuthorization fail");
	console.error(JSON.stringify(error));
	this.revokeAccessResult = "cancelAuthorization fail: " + JSON.stringify(error);
});- ForegroundManager
- getForegroundApi
 
 
ForegroundManager.getForegroundApi()
返回帐号对外开放页面接口实现对象
函数入参: 无
函数返回值:
| Type | Description | 
|---|---|
| ForegroundApi | 帐号对外开放页面接口实现对象 | 
示例代码:
import { ForegroundManager} from '@hw-hmscore/hms-jsb-account'
var foregroundApi =  ForegroundManager.getForegroundApi();- ForegroundApi
- getForegroundIntent(path, params)
 
 
ForegroundApi.getForegroundIntent()
帐号前台开放页面
函数入参:
| Type | Description | OptiOn | 
|---|---|---|
| HuaweiIdAuthParams | 鉴权参数对象,该对象一般不直接构造,而是使用 HuaweiIdAuthParamsHelper 通过构造者模式创建 | 必选 | 
| HuaweiIdGetTokenOptions | 如果用户希望获取 IdToken, 需要传入此参数 | 可选 | 
| Param | Type | Description | OptiOn | 
|---|---|---|---|
| path | String | 取值包含 ForegroundApis.PATH_REALNAME_INFO:实名列表页; ForegroundApis.PATH_REALNAME_FACE_VERIFY:人脸实名页; ForegroundApis.PATH_FACIAL_RECOGNITION_VERIFY:人脸核身页; | 必选 | 
| params | String | 传递给各页面的扩展参数,JSON格式。path为facialRecognitionVerify时,需要传verifyToken。 | 可选 | 
函数返回值:
| Type | Description | 
|---|---|
| Promise | 返回调用结果,path为facialRecognitionVerify时,结果中包含verifyResult字段,该值为JWT格式,可按JWT格式进行解析。 | 
示例代码:
import { ForegroundManager, ForegroundApis} from '@hw-hmscore/hms-jsb-account'
var params = {verifyToken:""}
ForegroundManager.getForegroundApi().getForegroundIntent(ForegroundApis.PATH_REALNAME_INFO, params).then((result)=>{
    //调用成功,返回对应信息
    console.info("getForegroundIntent success: " + result + "~~~~~~~~~");
    this.getForegroundIntentResult += "getForegroundIntent success: " + result + "~~~~~~~~~";
}).catch((error)=>{
    //调用失败
    console.error("getForegroundIntent fail: " + error + "~~~~~~~~~");
    this.getForegroundIntentResult += "getForegroundIntent fail: " + error + "~~~~~~~~~";
});6.11.0-300
2 years ago
6.10.1-300
3 years ago