From 70fcbee4ecef1f410f8eb70ec154bb760fa52801 Mon Sep 17 00:00:00 2001 From: jidong Date: Fri, 26 Aug 2022 19:39:21 +0800 Subject: [PATCH] modify account demo code Signed-off-by: jidong --- .../reference/apis/js-apis-appAccount.md | 28 +- .../reference/apis/js-apis-osAccount.md | 670 ++++++++---------- 2 files changed, 297 insertions(+), 401 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md index 8c78eb019a..0ea9524afc 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md +++ b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md @@ -899,7 +899,7 @@ getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo **示例:** ```js - const appAccountManager = account.createAppAccountManager(); + const appAccountManager = account_appAccount.createAppAccountManager(); const selfBundle = "com.example.actsgetallaaccounts"; appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ console.debug("getAllAccounts err:" + JSON.stringify(err)); @@ -960,7 +960,7 @@ on(type: 'change', owners: Array<string>, callback: Callback<Array<A **示例:** ```js - const appAccountManager = account.createAppAccountManager(); + const appAccountManager = account_appAccount.createAppAccountManager(); function changeOnCallback(data){ console.debug("receive change data:" + JSON.stringify(data)); } @@ -990,7 +990,7 @@ off(type: 'change', callback?: Callback>): void **示例:** ```js - const appAccountManager = account.createAppAccountManager(); + const appAccountManager = account_appAccount.createAppAccountManager(); function changeOnCallback(data){ console.debug("receive change data:" + JSON.stringify(data)); appAccountManager.off('change', function(){ @@ -1400,7 +1400,7 @@ getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenIn ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => { - console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); + console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); }).catch((err) => { console.log("getAllOAuthTokens err: " + JSON.stringify(err)); }); @@ -1495,7 +1495,7 @@ getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<Authentic [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.OnResult(account_appAccount.ResultCode.SUCCESS, result); + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); }); }); ``` @@ -1531,7 +1531,7 @@ getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.OnResult(account_appAccount.ResultCode.SUCCESS, result); + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); }).catch((err) => { console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); }); @@ -1733,7 +1733,8 @@ checkAccountLabels(name: string, owner: string, labels: Array<string>, cal ```js const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => { + var labels = ["student"]; + appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", labels, (err, data) => { console.log('checkAccountLabels: ' + JSON.stringify(data)); console.log("checkAccountLabels err: " + JSON.stringify(err)); }); @@ -1765,7 +1766,8 @@ checkAccountLabels(name: string, owner: string, labels: Array<string>): Pr ```js const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { + var labels = ["student"]; + appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", labels).then((data) => { console.log('checkAccountLabels: ' + JSON.stringify(data)); }).catch((err) => { console.log("checkAccountLabels err: " + JSON.stringify(err)); @@ -2115,7 +2117,7 @@ onResult: (code: number, result: {[key: string]: any}) => void [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.OnResult(account_appAccount.ResultCode.SUCCESS, result); + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); }).catch((err) => { console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); }); @@ -2168,7 +2170,7 @@ onRequestContinued?: () => void const appAccountManager = account_appAccount.createAppAccountManager(); var sessionId = "1234"; appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { - callback.OnRequestContinued(); + callback.onRequestContinued(); }).catch((err) => { console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); }); @@ -2295,7 +2297,7 @@ getRemoteObject(): rpc.RemoteObject; callback.onResult(account_appAccount.ResultCode.SUCCESS, result); } - verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback) { + verifyCredential(name, options, callback) { callback.onRequestRedirected({ bundleName: "com.example.ohos.accountjsdemo", abilityName: "com.example.ohos.accountjsdemo.VerifyAbility", @@ -2305,11 +2307,11 @@ getRemoteObject(): rpc.RemoteObject; }); } - setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback) { + setProperties(options, callback) { callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); } - checkAccountLabels(name: string, labels: Array, callback: AuthenticatorCallback) { + checkAccountLabels(name, labels, callback) { var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; callback.onResult(account_appAccount.ResultCode.SUCCESS, result); } diff --git a/zh-cn/application-dev/reference/apis/js-apis-osAccount.md b/zh-cn/application-dev/reference/apis/js-apis-osAccount.md index ba85e9643d..46c10df342 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-osAccount.md +++ b/zh-cn/application-dev/reference/apis/js-apis-osAccount.md @@ -440,12 +440,10 @@ removeOsAccount(localId: number, callback: AsyncCallback<void>): void ```js const accountManager = account_osAccount.getAccountManager(); - var createIocalId; - osAccountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ - createIocalId = osAccountInfo.localId; - }); - accountManager.removeOsAccount(createIocalId, (err)=>{ - console.log("removeOsAccount err:" + JSON.stringify(err)); + accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo) => { + accountManager.removeOsAccount(osAccountInfo.localId, (err)=>{ + console.log("removeOsAccount err:" + JSON.stringify(err)); + }); }); ``` @@ -477,15 +475,12 @@ removeOsAccount(localId: number): Promise<void> ```js const accountManager = account_osAccount.getAccountManager(); - var createIocalId; - osAccountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ - createIocalId = osAccountInfo.localId; - }); - createIocalId = osAccount.localId; - accountManager.removeOsAccount(createIocalId).then(() => { - console.log('removeOsAccount Success'); - }).catch(() => { - console.log("removeOsAccount err: " + JSON.stringify(err)); + accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + accountManager.removeOsAccount(osAccountInfo.localId).then(() => { + console.log('removeOsAccount Success'); + }).catch(() => { + console.log("removeOsAccount err: " + JSON.stringify(err)); + }); }); ``` @@ -1097,7 +1092,7 @@ createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback& ```js const accountManager = account_osAccount.getAccountManager(); - accountManager.createOsAccount("testName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + accountManager.createOsAccount("testName", account_osAccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ console.log("createOsAccount err:" + JSON.stringify(err)); console.log("createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); }); @@ -1132,7 +1127,7 @@ createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInf ```js const accountManager = account_osAccount.getAccountManager(); - accountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL).then((accountInfo) => { + accountManager.createOsAccount("testAccountName", account_osAccount.OsAccountType.NORMAL).then((accountInfo) => { console.log("createOsAccount, accountInfo: " + JSON.stringify(accountInfo)); }).catch((err) => { console.log("createOsAccount err: " + JSON.stringify(err)); @@ -1164,7 +1159,7 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, cal ```js const accountManager = account_osAccount.getAccountManager(); var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; - accountManager.createOsAccountForDomain(osaccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{ + accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{ console.log("createOsAccountForDomain err:" + JSON.stringify(err)); console.log("createOsAccountForDomain osAccountInfo:" + JSON.stringify(osAccountInfo)); }); @@ -1200,7 +1195,7 @@ createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Pr ```js const accountManager = account_osAccount.getAccountManager(); var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; - accountManager.createOsAccountForDomain(osaccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => { + accountManager.createOsAccountForDomain(account_osAccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => { console.log("createOsAccountForDomain, account info: " + JSON.stringify(accountInfo)); }).catch((err) => { console.log("createOsAccountForDomain err: " + JSON.stringify(err)); @@ -1523,7 +1518,7 @@ setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" - osAccountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ + accountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ console.log("setOsAccountProfilePhoto err:" + JSON.stringify(err)); }); ``` @@ -1765,8 +1760,9 @@ getBundleIdFromUid(uid: number, callback: AsyncCallback<number>): void; **示例:** ```js + const accountManager = account_osAccount.getAccountManager(); var testUid = 1000000; - osAccountManager.getBundleIdFromUid(testUid,(err,bundleId)=>{ + accountManager.getBundleIdFromUid(testUid, (err, bundleId) => { console.info("getBundleIdFromUid errInfo:" + JSON.stringify(err)); console.info("getBundleIdFromUid bundleId:" + JSON.stringify(bundleId)); }); @@ -1796,10 +1792,13 @@ getBundleIdFromUid(uid: number): Promise<number>; **示例:** ```js + const accountManager = account_osAccount.getAccountManager(); var testUid = 1000000; - var bundleIdInfo = await osAccountManager.getBundleIdFromUid(testUid).catch((err)=>{ - console.info("getBundleIdFromUid errInfo:" + JSON.stringify(err));}) - console.info("getBundleIdFromUid bundleId:" + JSON.stringify(bundleIdInfo)); + accountManager.getBundleIdFromUid(testUid).then((result) => { + console.info("getBundleIdFromUid bundleId:" + JSON.stringify(result)); + }).catch((err)=>{ + console.info("getBundleIdFromUid errInfo:" + JSON.stringify(err)); + }); ``` ### isMainOsAccount9+ @@ -1823,7 +1822,8 @@ isMainOsAccount(callback: AsyncCallback<boolean>): void; **示例:** ```js - osAccountManager.isMainOsAccount((err,result)=>{ + const accountManager = account_osAccount.getAccountManager(); + accountManager.isMainOsAccount((err,result)=>{ console.info("isMainOsAccount errInfo:" + JSON.stringify(err)); console.info("isMainOsAccount result:" + JSON.stringify(result)); }); @@ -1849,10 +1849,12 @@ isMainOsAccount(): Promise<boolean>; **示例:** ```js - var result = await osAccountManager.isMainOsAccount().catch((err)=>{ + const accountManager = account_osAccount.getAccountManager(); + accountManager.isMainOsAccount().then((result) => { + console.info("isMainOsAccount result:" + JSON.stringify(result)); + }).catch((err)=>{ console.info("isMainOsAccount errInfo:" + JSON.stringify(err)); }); - console.info("isMainOsAccount result:" + JSON.stringify(result)); ``` ### queryOsAccountConstraintSourceTypes9+ @@ -1877,7 +1879,8 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string, callbac **示例:** ```js - osAccountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi",(err,sourceTypeInfos)=>{ + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi",(err,sourceTypeInfos)=>{ console.info("queryOsAccountConstraintSourceType errInfo:" + JSON.stringify(err)); console.info("queryOsAccountConstraintSourceType sourceTypeInfos:" + JSON.stringify(sourceTypeInfos)); }); @@ -1911,9 +1914,12 @@ queryOsAccountConstraintSourceTypes(localId: number, constraint: string): Promis **示例:** ```js - var sourceTypeInfos = await osAccountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi").catch((err)=>{ - console.info("queryOsAccountConstraintSourceType errInfo:" + JSON.stringify(err));}) - console.info("queryOsAccountConstraintSourceType sourceTypeInfos:" + JSON.stringify(sourceTypeInfos)); + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryOsAccountConstraintSourceTypes(100, "constraint.wifi").then((result) => { + console.info("queryOsAccountConstraintSourceType sourceTypeInfos:" + JSON.stringify(result)); + }).catch((err)=>{ + console.info("queryOsAccountConstraintSourceType errInfo:" + JSON.stringify(err)); + }); ``` ## UserAuth8+ @@ -1934,8 +1940,7 @@ constructor() **示例:** ```js - let userAuth = new osAccount.UserAuth(); - console.info('====>test for examples constructor success'); + let userAuth = new account_osAccount.UserAuth(); ``` @@ -1957,10 +1962,9 @@ getVersion(): number; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - console.info('====>test for examples constructor success'); - var version = userAuth.getVersion(); - console.info('====>test for examples version is : ' + JSON.stringify(version)); + let userAuth = new account_osAccount.UserAuth(); + let version = userAuth.getVersion(); + console.log("getVersion version = " + version); ``` ### getAvailableStatus8+ @@ -1990,12 +1994,11 @@ getAvailableStatus(authType: AuthType, authTrustLevel: AuthTrustLevel): number; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let authTrustLevel = osAccount.AuthTrustLevel.ATL1; - console.info('====>test for examples constructor success'); - let availableStatus = userAuth.getAvailableStatus(authType, authTrustLevel); - console.info('====>test for examples AvailabeStatus is : ' + JSON.stringify(availableStatus)); + let userAuth = new account_osAccount.UserAuth(); + let authType = account_osAccount.AuthType.PIN; + let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; + let status = userAuth.getAvailableStatus(authType, authTrustLevel); + console.log("getAvailableStatus status = " + status); ``` ### getProperty8+ @@ -2019,16 +2022,20 @@ getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProp **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let keys = new Array(); - keys[0] = osAccount.GetPropertyType.AUTH_SUB_TYPE; - keys[1] = osAccount.GetPropertyType.REMAIN_TIMES; - keys[2] = osAccount.GetPropertyType.FREEZING_TIME; - let getPropertyRequest = {authType, keys}; - userAuth.getProperty(getPropertyRequest,function (propReq) { - console.log("====>test for examples getallAuthInfo AsyncCallback = " + JSON.stringify(propReq)); - }) + let userAuth = new account_osAccount.UserAuth(); + let keys = [ + account_osAccount.GetPropertyType.AUTH_SUB_TYPE, + account_osAccount.GetPropertyType.REMAIN_TIMES, + account_osAccount.GetPropertyType.FREEZING_TIME + ]; + let request = { + authType: account_osAccount.AuthType.PIN, + keys: keys + }; + userAuth.getProperty(request, (err, result) => { + console.log("getProperty err = " + JSON.stringify(err)); + console.log("getProperty result = " + JSON.stringify(result)); + }); ``` ### getProperty8+ @@ -2057,15 +2064,20 @@ getProperty(request: GetPropertyRequest): Promise<ExecutorProperty>; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let keys = new Array(); - keys[0] = osAccount.GetPropertyType.AUTH_SUB_TYPE; - keys[1] = osAccount.GetPropertyType.REMAIN_TIMES; - keys[2] = osAccount.GetPropertyType.FREEZING_TIME; - let getPropertyRequest = {authType, keys}; - userAuth.getProperty(getPropertyRequest).then((propReq) => { - console.log("====>test for examples getallAuthInfo AsyncCallback = " + JSON.stringify(propReq)); + let userAuth = new account_osAccount.UserAuth(); + let keys = [ + account_osAccount.GetPropertyType.AUTH_SUB_TYPE, + account_osAccount.GetPropertyType.REMAIN_TIMES, + account_osAccount.GetPropertyType.FREEZING_TIME + ]; + let request = { + authType: account_osAccount.AuthType.PIN, + keys: keys + }; + userAuth.getProperty(request).then((result) => { + console.log("getProperty result = " + JSON.stringify(result)); + }).catch((err) => { + console.log("getProperty error = " + JSON.stringify(err)); }); ``` @@ -2090,13 +2102,15 @@ setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let key = osAccount.SetPropertyType.INIT_ALGORITHM; - let setInfo = new Uint8Array(); - let setPropertyRequest = {authType, key, setInfo}; - userAuth.setProperty(setPropertyRequest,function (setProp) { - console.log("====>test for examples setProperty AsyncCallback = " + JSON.stringify(setProp)); + let userAuth = new account_osAccount.UserAuth(); + let request = { + authType: account_osAccount.AuthType.PIN, + key: account_osAccount.SetPropertyType.INIT_ALGORITHM, + setInfo: new Uint8Array([0]) + }; + userAuth.setProperty(request, (err, result) => { + console.log("setProperty error = " + JSON.stringify(err)); + console.log("setProperty result = " + JSON.stringify(result)); }); ``` @@ -2126,13 +2140,16 @@ setProperty(request: SetPropertyRequest): Promise<number>; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let key = osAccount.SetPropertyType.INIT_ALGORITHM; - let setInfo = new Uint8Array(); - let setPropertyRequest = {authType, key, setInfo}; - userAuth.setProperty(setPropertyRequest).then((setProp) => { - console.log("====>test for examples setProperty AsyncCallback = " + JSON.stringify(setProp)); + let userAuth = new account_osAccount.UserAuth(); + let request = { + authType: account_osAccount.AuthType.PIN, + key: account_osAccount.SetPropertyType.INIT_ALGORITHM, + setInfo: new Uint8Array([0]) + }; + userAuth.setProperty(request).then((result) => { + console.log("setProperty result = " + JSON.stringify(result)); + }).catch((err) => { + console.log("setProperty error = " + JSON.stringify(err)); }); ``` @@ -2166,22 +2183,15 @@ auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let challenge = 1; - let authTrustLevel = osAccount.AuthTrustLevel.ATL1; - let onresult = { - authresult: null, - authextr: null, - } - userAuth.auth(challenge, authType,authTrustLevel,{ - onResult: function(result,extraInfo){ - console.log("====>test for examples auth result = " + result); - onresult.authresult = result; - console.log("====>test for examples auth extraInfo = " + JSON.stringify(extraInfo)); - onresult.authextr = extraInfo; - console.info('====>test for examples auth onResult = ' + JSON.stringify(onresult)); - } + let userAuth = new account_osAccount.UserAuth(); + let challenge = new Uint8Array([0]); + let authType = account_osAccount.AuthType.PIN; + let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; + userAuth.auth(challenge, authType, authTrustLevel, { + onResult: function(result,extraInfo){ + console.log("auth result = " + result); + console.log("auth extraInfo = " + JSON.stringify(extraInfo)); + } }); ``` @@ -2216,23 +2226,16 @@ authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLev **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let challenge = 1; - let authTrustLevel = osAccount.AuthTrustLevel.ATL1; + let userAuth = new account_osAccount.UserAuth(); let userID = 100; - let onresult = { - authresult: null, - authextr: null, - } + let challenge = new Uint8Array([0]); + let authType = account_osAccount.AuthType.PIN; + let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; userAuth.authUser(userID, challenge, authType, authTrustLevel, { - onResult: function(result,extraInfo){ - console.log("====>test for examples authUser result = " + result); - onresult.authresult = result; - console.log("====>test for examples authUser extraInfo = " + JSON.stringify(extraInfo)); - onresult.authextr = extraInfo; - console.info('====>test for examples authUser onResult = ' + JSON.stringify(onresult)); - } + onResult: function(result,extraInfo){ + console.log("authUser result = " + result); + console.log("authUser extraInfo = " + JSON.stringify(extraInfo)); + } }); ``` @@ -2262,11 +2265,17 @@ cancelAuth(contextID: Uint8Array): number; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let contextID = null; - let cancelAuthresult = null; - cancelAuthresult = userAuth.cancelAuth(contextID); - console.log("====>test for examples cancelAuthresult result = " + JSON.stringify(cancelAuthresult)); + let userAuth = new account_osAccount.UserAuth(); + let pinAuth = new account_osAccount.PINAuth(); + let challenge = new Uint8Array([0]); + let contextID = userAuth.auth(challenge, account_osAccount.AuthType.PIN, account_osAccount.AuthTrustLevel.ATL1, { + onResult: (result, extraInfo) => { + console.log("auth result = " + result); + console.log("auth extraInfo = " + JSON.stringify(extraInfo)); + } + }); + let result = userAuth.cancelAuth(contextID); + console.log("cancelAuth result = " + result); ``` ## PINAuth8+ @@ -2287,8 +2296,7 @@ constructor() **示例:** ```js - var pinAuth = new osAccount.PINAuth(); - console.info('====>test for examples constructor success'); + let pinAuth = new account_osAccount.PINAuth(); ``` ### registerInputer @@ -2317,20 +2325,14 @@ registerInputer(inputer: IInputer): boolean; **示例:** ```js - var pinAuth = new osAccount.PINAuth(); - var GetAuthSubType = 0; - var AuthSubType = osAccount.AuthSubType.PIN_SIX; - var Inputerdata = [0,1,3]; - var registerresult = pinAuth.registerInputer({ - onGetData: (GetAuthSubType, IInputData) => { - if (GetAuthSubType == 0) { - IInputData.onSetData(AuthSubType, Inputerdata) - } else { - IInputData.onSetData(GetAuthSubType, Inputerdata); - } + let pinAuth = new account_osAccount.PINAuth(); + let password = new Uint8Array([0, 0, 0, 0, 0]; + let result = pinAuth.registerInputer({ + onGetData: (pinSubType, callback) => { + callback.onSetData(pinSubType, password); } - }) - console.log("====>test for examples RegisterInputer result is: " + registerresult); + }); + console.log("registerInputer result = " + result); ``` ### unregisterInputer @@ -2347,7 +2349,7 @@ unregisterInputer(): void; **示例:** ```js - var pinAuth = new osAccount.PinAuth(); + let pinAuth = new account_osAccount.PINAuth(); pinAuth.unregisterInputer(); ``` @@ -2369,8 +2371,7 @@ constructor() **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - console.info('====>test for examples constructor success'); + let userIDM = new account_osAccount.UserIdentityManager(); ``` ### openSession8+ @@ -2393,19 +2394,10 @@ openSession(callback: AsyncCallback<Uint8Array>): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - var challenge; - userIDM.openSession(function(err, data){ - try{ - console.log("====>test for examples before get challenge"); - console.log("====>test for examples + " + data); - challenge = data; - console.log("====>test for examples end "); - console.log("====>test for examples after get challenge"); - } - catch(e) { - console.info('====>test for examples openSession error = ' + JSON.stringify(e)); - } + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.openSession((err, challenge) => { + console.log("openSession error = " + JSON.stringify(err)); + console.log("openSession challenge = " + JSON.stringify(challenge)); }); ``` @@ -2429,23 +2421,12 @@ openSession(): Promise<Uint8Array>; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - var challenge; - userIDM.openSession().then((data) => { - try{ - console.log("====>test for examples before get challenge"); - console.log("====>test for examples + " + data); - challenge = data; - console.log("====>test for examples end "); - console.log("====>test for examples after get challenge"); - } - catch(err) { - console.info('====>test for examples faceDemo openSession error1 = ' + JSON.stringify(err)); - } - }) - .catch((err) => { - console.info('====>test for examples faceDemo openSession error2 = ' + JSON.stringify(err)); - }) + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.openSession().then((challenge) => { + console.info("openSession challenge = " + JSON.stringify(challenge)); + }).catch((err) => { + console.info("openSession error = " + JSON.stringify(err)); + }); ``` ### addCredential8+ @@ -2469,26 +2450,27 @@ addCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let CredentialInfo = null; - let onresult = { - addCredresult: null, - credentialId: null, - } - userIDM.addCredential(CredentialInfo, { - onResult: function(result,extraInfo){ - console.info('====>test for examples aaaaaaaaaaaaa'); - console.info("====>test for examples addCredential result = " + result); - console.info("====>test for examples addCredential extraInfo = " + JSON.stringify(extraInfo)); - console.log(result) - onresult.addCredresult= result; - if(extraInfo != undefined) { - onresult.credentialId = extraInfo.credentialId - } else { - onresult.credentialId = null; - } + let password = new Uint8Array([0, 0, 0, 0, 0, 0]); + let pinAuth = new account_osAccount.PINAuth(); + pinAuth.registerInputer({ + onGetData: (pinSubType, callback) => { + callback.onSetData(pinSubType, password); + } + }); + let credentialInfo = { + credType: account_osAccount.AuthType.PIN, + credSubType: account_osAccount.AuthSubType.PIN_SIX, + token: null + }; + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.openSession((err, challenge) => { + userIDM.addCredential(credentialInfo, { + onResult: (result, extraInfo) => { + console.log("updateCredential result = " + result); + console.log("updateCredential extraInfo = " + extraInfo); } - }) + }); + }); ``` ### updateCredential8+ @@ -2512,25 +2494,36 @@ updateCredential(credentialInfo: CredentialInfo, callback: IIdmCallback): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let CredentialInfo = null; - let onresult = { - addCredresult: null, - credentialId: null, - } - userIDM.updateCredential(CredentialInfo, { - onResult: function(result,extraInfo){ - console.log("====>test for examples faceDemo updateCredential result = " + result) - onresult.updateCredresult = result - console.log("====>test for examples faceDemo updateCredential credentialId = " + extraInfo.credentialId) - if(extraInfo != undefined) { - onresult.CredentialId = extraInfo.credentialId - } else { - onresult.CredentialId = null; + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let pinAuth = new account_osAccount.PINAuth(); + let password = new Uint8Array([0, 0, 0, 0, 0, 0]); + let credentialInfo = { + credType: account_osAccount.AuthType.PIN, + credSubType: account_osAccount.AuthSubType.PIN_SIX, + token: null + }; + pinAuth.registerInputer({ + onGetData: (pinSubType, callback) => { + callback.onSetData(pinSubType, password); + } + }); + userIDM.openSession((err, challenge) => { + userAuth.auth(challenge, credentialInfo.credType, account_osAccount.AuthTrustLevel.ATL_1, { + onResult: (result, extraInfo) => { + if (result != account_osAccount.ResultCode.SUCCESS) { + return; + } + credentialInfo.token = extraInfo.token; + userIDM.updateCredential(credentialInfo, { + onResult: (result, extraInfo) => { + console.log("updateCredential result = " + result); + console.log("updateCredential extraInfo = " + extraInfo); } - console.info('====>test for examples publicupdateCred updateCredential onResult = ' + JSON.stringify(onresult)); + }); } - }) + }); + }); ``` ### closeSession8+ @@ -2547,7 +2540,7 @@ closeSession(): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); + let userIDM = new account_osAccount.UserIdentityManager(); userIDM.closeSession(); ``` @@ -2577,7 +2570,7 @@ cancel(challenge: Uint8Array): number; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); + let userIDM = new account_osAccount.UserIdentityManager(); let challenge = 1; let cancelresult = userIDM.cancel(challenge); ``` @@ -2603,24 +2596,14 @@ delUser(token: Uint8Array, callback: IIdmCallback): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let onresult = { - delUserresult: null, - CredentialId: null, - } - let token = null; + let userIDM = new account_osAccount.UserIdentityManager(); + let token = new Uint8Array([0]); userIDM.delUser(token, { - onResult: function(result,extraInfo){ - console.log("====>test for examples delUser result = " + result) - onresult.delUserresult = result - if(extraInfo != undefined) { - onresult.CredentialId = extraInfo.credentialId - } else { - onresult.CredentialId = null; - } - console.info('====>test for examples publicdelUser delUser = ' + JSON.stringify(onresult)); - } - }) + onResult: (result, extraInfo) => { + console.log("delUser result = " + result); + console.log("delUser extraInfo = " + JSON.stringify(extraInfo)); + } + }); ``` ### delCred8+ @@ -2645,26 +2628,15 @@ delCred(credentialId: Uint8Array, token: Uint8Array, callback: IIdmCallback): vo **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let onresult = { - delUserresult: null, - CredentialId: null, - } - let credentialId = 1; - let token = null; - userIDM.delCred(credentialId, token,{ - onResult: function(result,extraInfo){ - console.log("====>test for examples delCred result = " + result) - onresult.delCredresult = result - console.log("====>test for examples delCred extraInfo = " + extraInfo) - if(extraInfo != undefined) { - onresult.CredentialId = extraInfo.credentialId - } else { - onresult.CredentialId = null; - } - console.log("====>test for examples delCred onresult = " + JSON.stringify(onresult)); - } - }) + let userIDM = new account_osAccount.UserIdentityManager(); + let credentialId = new Uint8Array([0]); + let token = new Uint8Array([0]); + userIDM.delCred(credentialId, token, { + onResult: (result, extraInfo) => { + console.log("delCred result = " + result); + console.log("delCred extraInfo = " + JSON.stringify(extraInfo)); + } + }); ``` ### getAuthInfo8+ @@ -2688,11 +2660,11 @@ getAuthInfo(callback: AsyncCallback<Array<EnrolledCredInfo>>): void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - var authType = osAccount.AuthType.PIN; - userIDM.getAuthInfo(function (authInfo) { - console.log("====>test for examples getAuthInfo AsyncCallback = " + JSON.stringify(authInfo)) - }) + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.getAuthInfo((err, result) => { + console.log("getAuthInfo err = " + JSON.stringify(err)); + console.log("getAuthInfo result = " + JSON.stringify(result)); + }); ``` ### getAuthInfo8+ @@ -2716,11 +2688,11 @@ getAuthInfo(authType: AuthType, callback: AsyncCallback<Array<EnrolledCred **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - var authType = osAccount.AuthType.PIN; - userIDM.getAuthInfo(authType, function (authInfo) { - console.log("====>test for examples getAuthInfo AsyncCallback = " + JSON.stringify(authInfo)) - }) + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.getAuthInfo(account_osAccount.AuthType.PIN, (err, result) => { + console.log("getAuthInfo err = " + JSON.stringify(err)); + console.log("getAuthInfo result = " + JSON.stringify(result)); + }); ``` ### getAuthInfo8+ @@ -2749,11 +2721,12 @@ getAuthInfo(authType?: AuthType): Promise<Array<EnrolledCredInfo>>; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - var authType = osAccount.AuthType.PIN; - userIDM.getAuthInfo(authType).then((authInfo) => { - console.log("====>test for examples getAuthInfo AsyncCallback = " + JSON.stringify(authInfo)) - }) + let userIDM = new account_osAccount.UserIdentityManager(); + userIDM.getAuthInfo(account_osAccount.AuthType.PIN).then((result) => { + console.log("getAuthInfo result = " + JSON.stringify(result)) + }).catch((err) => { + console.log("getAuthInfo error = " + JSON.stringify(err)); + }); ``` ## IInputData8+ @@ -2781,26 +2754,17 @@ onSetData: (pinSubType: AuthSubType, data: Uint8Array) => void; **示例:** ```js - console.log("====>test for examples onCreate start "); - var pinAuth = new osAccount.PINAuth(); - var GetAuthSubType = 0; - var AuthSubType = osAccount.AuthSubType.PIN_SIX; - console.log("====>test for examples GetAuthSubType " + GetAuthSubType); - console.log("====>test for examples AuthSubType " + AuthSubType); - var Inputerdata = [0,1,3]; - var registerresult = pinAuth.registerInputer({ - onGetData: (GetAuthSubType, IInputData) => { - console.log("====>test for examples by GetAuthSubType " +GetAuthSubType ); - if (GetAuthSubType == 0) { - console.log("====>test for examples GetAuthSubType == 0 "); - IInputData.onSetData(AuthSubType, Inputerdata) - } else { - console.log("====>test for examples GetAuthSubType == 1 "); - IInputData.onSetData(GetAuthSubType, Inputerdata); - } - } - }) - console.log("====>test for examples RegisterInputer result is: " + registerresult); + let password = new Uint8Array([0, 0, 0, 0, 0, 0]); + let passwordNumber = new Uint8Array([1, 2, 3, 4]); + let inputer = { + onGetData: (pinSubType, callback) => { + if (pinSubType == account_osAccount.AuthSubType.PIN_NUMBER) { + callback.onSetData(pinSubType, passwordNumber); + } else { + callback.onSetData(pinSubType, password); + } + } + }; ``` ## IInputer8+ @@ -2827,26 +2791,20 @@ onGetData: (pinSubType: AuthSubType, callback: IInputData) => void; **示例:** ```js - console.log("====>test for examples onCreate start "); - var pinAuth = new osAccount.PINAuth(); - var GetAuthSubType = 0; - var AuthSubType = osAccount.AuthSubType.PIN_SIX; - console.log("====>test for examples GetAuthSubType " + GetAuthSubType); - console.log("====>test for examples AuthSubType " + AuthSubType); - var Inputerdata = [0,1,3]; - var registerresult = pinAuth.registerInputer({ - onGetData: (GetAuthSubType, IInputData) => { - console.log("====>test for examples by GetAuthSubType " +GetAuthSubType ); - if (GetAuthSubType == 0) { - console.log("====>test for examples GetAuthSubType == 0 "); - IInputData.onSetData(AuthSubType, Inputerdata) - } else { - console.log("====>test for examples GetAuthSubType == 1 "); - IInputData.onSetData(GetAuthSubType, Inputerdata); - } - } - }) - console.log("====>test for examples RegisterInputer result is: " + registerresult); + let password = new Uint8Array([0, 0, 0, 0, 0, 0]); + let passwordNumber = new Uint8Array([1, 2, 3, 4]); + let inputer = { + onGetData: (pinSubType, callback) => { + if (pinSubType == account_osAccount.AuthSubType.PIN_NUMBER) { + callback.onSetData(pinSubType, passwordNumber); + } else { + callback.onSetData(pinSubType, password); + } + } + }; + let pinAuth = new account_osAccount.PINAuth(); + let result = pinAuth.registerInputer(inputer); + console.log("registerInputer result: " + result); ``` ## IUserAuthCallback8+ @@ -2874,23 +2832,12 @@ onResult: (result: number, extraInfo: AuthResult) => void; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let challenge = 1; - let authTrustLevel = osAccount.AuthTrustLevel.ATL1; - let onresult = { - authresult: null, - authextr: null, - } - userAuth.auth(challenge, authType,authTrustLevel,{ - onResult: function(result,extraInfo){ - console.log("====>test for examples auth result = " + result); - onresult.authresult = result; - console.log("====>test for examples auth extraInfo = " + JSON.stringify(extraInfo)); - onresult.authextr = extraInfo; - console.info('====>test for examples auth onResult = ' + JSON.stringify(onresult)); - } - }); + let authCallback = { + onResult: (result, extraInfo) => { + console.log("auth result = " + result); + console.log("auth extraInfo = " + JSON.stringify(extraInfo)); + } + }; ``` ### onAcquireInfo?8+ @@ -2913,36 +2860,17 @@ onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void; **示例:** ```js - let userAuth = new osAccount.UserAuth(); - let authType = osAccount.AuthType.PIN; - let challenge = 1; - let authTrustLevel = osAccount.AuthTrustLevel.ATL1; - let onresult = { - authresult: null, - authextr: null, - } - let onacquireinfo = { - authmodule : null, - authacquire : null, - authextr : null - } - userAuth.auth(challenge, authType,authTrustLevel,{ - onResult: function(result,extraInfo){ - console.log("====>test for examples auth result = " + result) - onresult.authresult = result - console.log("====>test for examples auth extraInfo = " + JSON.stringify(extraInfo)); - onresult.authextr = extraInfo; - console.info('====>test for examples auth onResult = ' + JSON.stringify(onresult)); - }, - onAcquireInfo:function (modulea,acquire,extr){ - console.info('====>test for examples publicauth auth onAcquireInfo in'); - onacquireinfo.authmodule = modulea; - onacquireinfo.authacquire = acquire; - onacquireinfo.authextr = extr; - console.log("====>test for examples auth module = " + JSON.stringify(modulea)); - console.info('====>test for examples publicauth auth onAcquireInfo = ' + JSON.stringify(onacquireinfo)); - } - }); + let authCallback = { + onResult: (result, extraInfo) => { + console.log("auth result = " + result) + console.log("auth extraInfo = " + JSON.stringify(extraInfo)); + }, + onAcquireInfo: (module, acquire, extraInfo) => { + console.log("auth module = " + module); + console.log("auth acquire = " + acquire); + console.info('auth extraInfo = ' + JSON.stringify(extraInfo)); + } + }; ``` ## IIdmCallback8+ @@ -2970,25 +2898,12 @@ onResult: (result: number, extraInfo: RequestResult) => void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let CredentialInfo = null; - let onresult = { - addCredresult: null, - credentialId: null, - } - userIDM.updateCredential(CredentialInfo, { - onResult: function(result,extraInfo){ - console.log("====>test for examples updateCredential result = " + result) - onresult.updateCredresult = result - console.log("====>test for examples updateCredential credentialId = " + extraInfo.credentialId) - if(extraInfo != undefined) { - onresult.CredentialId = extraInfo.credentialId - } else { - onresult.CredentialId = null; - } - console.info('====>test for examples publicupdateCred updateCredential onResult = ' + JSON.stringify(onresult)); - } - }) + var idmCallback = { + onResult: (result, extraInfo) => { + console.log("callback result = " + result) + console.info('callback extraInfo = ' + JSON.stringify(extraInfo)); + } + }; ``` ### onAcquireInfo?8+ @@ -3011,38 +2926,17 @@ onAcquireInfo?: (module: number, acquire: number, extraInfo: any) => void; **示例:** ```js - var userIDM = new osAccount.UserIdentityManager(); - let CredentialInfo = null; - let onresult = { - addCredresult: null, - credentialId: null, - } - let onacquireinfo = { - updateCredmodule : null, - updateCredacquire : null, - updateCredextr : null - } - userIDM.updateCredential(CredentialInfo, { - onResult: function(result,extraInfo){ - console.log("====>test for examples updateCredential result = " + result) - onresult.updateCredresult = result - console.log("====>test for examples updateCredential credentialId = " + extraInfo.credentialId) - if(extraInfo != undefined) { - onresult.CredentialId = extraInfo.credentialId - } else { - onresult.CredentialId = null; - } - console.info('====>test for examples publicupdateCred updateCredential onResult = ' + JSON.stringify(onresult)); - }, - onAcquireInfo:function (modulea,acquire,extr){ - console.info('====>test for examples publicupdateCred updateCredential onAcquireInfo in '); - onacquireinfo.updateCredmodule = modulea - onacquireinfo.updateCredacquire = acquire - onacquireinfo.updateCredextr = extr - console.info('====>test for examples updateCredential onacquireinfo = ' + JSON.stringify(onacquireinfo)); - console.log("====>test for examples updateCredential module = " + modulea) - } - }) + let idmCallback = { + onResult: (result, extraInfo) => { + console.log("callback result = " + result) + console.log("callback onResult = " + JSON.stringify(extraInfo)); + }, + onAcquireInfo: (module, acquire, extraInfo) => { + console.log("callback module = " + module); + console.log("callback acquire = " + acquire); + console.log('callback onacquireinfo = ' + JSON.stringify(extraInfo)); + } + }; ``` ## GetPropertyRequest8+ -- GitLab