0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙開發(fā)設備管理:ohos.account.appAccount 應用帳號管理

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-07-06 10:43 ? 次閱讀

應用帳號管理

icon-note.gif說明: 本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。 開發(fā)前請熟悉鴻蒙開發(fā)指導文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

導入模塊

import account_appAccount from '@ohos.account.appAccount';

account_appAccount.createAppAccountManager

createAppAccountManager(): AppAccountManager

應用帳號管理:獲取應用帳號模塊對象。

系統(tǒng)能力: SystemCapability.Account.AppAccount

返回值:

類型說明
AppAccountManager獲取應用帳號模塊的實例。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();

AppAccountManager

管理應用帳號模塊的實例。

addAccount

addAccount(name: string, callback: AsyncCallback): void

將此應用的帳號名添加到帳號管理服務中,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù)

參數(shù)名類型必填說明
namestring要添加的應用帳戶的名稱。
callbackAsyncCallback將此應用的帳號名添加到帳號管理服務的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.addAccount("WangWu", (err) = > { 
    console.log("addAccount err: " + JSON.stringify(err));
});

addAccount

addAccount(name: string, extraInfo: string, callback: AsyncCallback): void

將此應用程序的帳號名和額外信息添加到帳號管理服務中,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要添加的應用帳戶的名稱。
extraInfostring要添加的應用帳戶的額外信息(例如token等),額外的信息不能是應用帳號的敏感信息。
callbackAsyncCallback將此應用程序的帳號名和額外信息添加到帳號管理服務中的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.addAccount("LiSi", "token101", (err) = > { 
    console.log("addAccount err: " + JSON.stringify(err));
});

addAccount

addAccount(name: string, extraInfo?: string): Promise

將此應用的帳號名或額外信息添加到帳號管理服務中,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要添加的應用帳戶的名稱。
extraInfostring要添加的應用帳戶的額外信息,額外的信息不能是應用帳號的敏感信息。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.addAccount("LiSi", "token101").then(()= > { 
    console.log('addAccount Success');
}).catch((err) = > {
    console.log("addAccount err: "  + JSON.stringify(err));
});

addAccountImplicitly8+

addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

根據(jù)指定的帳號所有者、鑒權類型和可選項,隱式地添加應用帳號,并使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
ownerstring要添加的應用帳戶的所有者包名。
authTypestring要添加的應用帳戶的鑒權類型。
options{[key: string]: any}鑒權所需要的可選項。
callbackAuthenticatorCallback認證器回調(diào),用于返回鑒權結果。

示例:

import featureAbility from '@ohos.ability.featureAbility';

function onResultCallback(code, result) {
    console.log("resultCode: "  + code);
    console.log("result: "  + JSON.stringify(result));
}

function onRequestRedirectedCallback(request) {
    let abilityStartSetting = {want: request};
    featureAbility.startAbility(abilityStartSetting, (err)= >{
        console.log("startAbility err: " + JSON.stringify(err));
    });
}

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.addAccountImplicitly("LiSi", "readAge", {}, {
    onResult: onResultCallback,
    onRequestRedirected: onRequestRedirectedCallback
});

deleteAccount

deleteAccount(name: string, callback: AsyncCallback): void

從帳號管理服務中刪除應用帳號,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要刪除的應用帳戶的名稱。
callbackAsyncCallback帳號管理服務中刪除應用帳號的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.deleteAccount("ZhaoLiu", (err) = > { 
    console.log("deleteAccount err: " + JSON.stringify(err));
 });

deleteAccount

deleteAccount(name: string): Promise

從帳號管理服務中刪除應用帳號,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要刪除的應用帳戶的名稱。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.deleteAccount("ZhaoLiu").then(() = > { 
      console.log('deleteAccount Success');
 }).catch((err) = > {
    console.log("deleteAccount err: "  + JSON.stringify(err));
});

disableAppAccess

disableAppAccess(name: string, bundleName: string, callback: AsyncCallback): void

禁止指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要禁用訪問的第三方應用帳戶的名稱。
bundleNamestring第三方應用的包名。
callbackAsyncCallback禁止指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) = > { 
    console.log("disableAppAccess err: " + JSON.stringify(err));
});

disableAppAccess

disableAppAccess(name: string, bundleName: string): Promise

禁止指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要禁用訪問的第三方應用帳戶的名稱。
bundleNamestring第三方應用的包名。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() = > { 
    console.log('disableAppAccess Success');
}).catch((err) = > {
    console.log("disableAppAccess err: "  + JSON.stringify(err));
});

enableAppAccess

enableAppAccess(name: string, bundleName: string, callback: AsyncCallback): void

允許指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
bundleNamestring第三方應用的包名。
callbackAsyncCallback允許指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) = > { 
    console.log("enableAppAccess: " + JSON.stringify(err));
 });

enableAppAccess

enableAppAccess(name: string, bundleName: string): Promise

允許指定第三方應用帳戶的名稱訪問指定包名稱的第三方應用,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
bundleNamestring第三方應用的包名。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

app_account_instance.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() = > { 
     console.log('enableAppAccess Success');
}).catch((err) = > {
    console.log("enableAppAccess err: "  + JSON.stringify(err));
});

checkAppAccountSyncEnable

checkAppAccountSyncEnable(name: string, callback: AsyncCallback): void

檢查指定應用帳號是否允許應用數(shù)據(jù)同步,使用callback回調(diào)異步返回結果。

需要權限: ohos.permission.DISTRIBUTED_DATASYNC,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
callbackAsyncCallback檢查指定應用帳號是否允許應用數(shù)據(jù)同步的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) = > { 
    console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
    console.log('checkAppAccountSyncEnable result: ' + result);
});

checkAppAccountSyncEnable

checkAppAccountSyncEnable(name: string): Promise

檢查指定應用帳號是否允許應用數(shù)據(jù)同步,使用Promise方式異步返回結果。

需要權限: ohos.permission.DISTRIBUTED_DATASYNC,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) = > { 
    console.log('checkAppAccountSyncEnable, result: ' + data);
}).catch((err) = > {
    console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
});

setAccountCredential

setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback): void

設置此應用程序帳號的憑據(jù),使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用程序帳戶的名稱。
credentialTypestring要設置的憑據(jù)的類型。
credentialstring要設置的憑據(jù)。
callbackAsyncCallback設置此應用帳號的憑據(jù)的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) = > { 
    console.log("setAccountCredential err: " + JSON.stringify(err));
});

setAccountCredential

setAccountCredential(name: string, credentialType: string, credential: string): Promise

設置此應用程序帳號的憑據(jù),使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
credentialTypestring要設置的憑據(jù)的類型。
credentialstring要設置的憑據(jù)。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() = > { 
    console.log('setAccountCredential Success');
}).catch((err) = > {
    console.log("setAccountCredential err: "  + JSON.stringify(err));
});

setAccountExtraInfo

setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback): void

設置此應用程序帳號的額外信息,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
extraInfostring要設置的額外信息。
callbackAsyncCallback設置此應用帳號的額外信息的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) = > { 
    console.log("setAccountExtraInfo err: " + JSON.stringify(err));
});

setAccountExtraInfo

setAccountExtraInfo(name: string, extraInfo: string): Promise

設置此應用程序帳號的額外信息,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
extraInfostring要設置的額外信息。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() = > { 
    console.log('setAccountExtraInfo Success');
}).catch((err) = > {
    console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
});

setAppAccountSyncEnable

setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback): void

設置指定的應用程序帳號是否允許應用程序數(shù)據(jù)同步,使用callback回調(diào)異步返回結果。

需要權限: ohos.permission.DISTRIBUTED_DATASYNC,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
isEnableboolean是否允許應用數(shù)據(jù)同步。
callbackAsyncCallback設置指定的應用帳號是否允許應用程序數(shù)據(jù)同步的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) = > { 
    console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
});

setAppAccountSyncEnable

setAppAccountSyncEnable(name: string, isEnable: boolean): Promise

設置指定的應用程序帳號是否允許應用程序數(shù)據(jù)同步,使用Promise方式異步返回結果。

需要權限: ohos.permission.DISTRIBUTED_DATASYNC,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
isEnableboolean是否允許應用數(shù)據(jù)同步。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() = > { 
    console.log('setAppAccountSyncEnable Success');
}).catch((err) = > {
    console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
});

setAssociatedData

setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback): void

設置與此應用程序帳號關聯(lián)的數(shù)據(jù),使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
keystring要設置的數(shù)據(jù)的鍵,密鑰可以自定義。
valuestring要設置的數(shù)據(jù)的值。
callbackAsyncCallback設置與此應用帳號關聯(lián)的數(shù)據(jù)的回調(diào)。

示例:

app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) = > { 
    console.log("setAssociatedData err: " + JSON.stringify(err));
});

setAssociatedData

setAssociatedData(name: string, key: string, value: string): Promise

設置與此應用程序帳號關聯(lián)的數(shù)據(jù),使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
keystring要設置的數(shù)據(jù)的鍵,密鑰可以自定義。
valuestring要設置的數(shù)據(jù)的值。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() = > { 
    console.log('setAssociatedData Success');
}).catch((err) = > {
    console.log("setAssociatedData err: "  + JSON.stringify(err));
});

getAccountCredential

getAccountCredential(name: string, credentialType: string, callback: AsyncCallback): void

獲取此應用帳號的憑據(jù),使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
credentialTypestring要獲取的憑據(jù)的類型。
callbackAsyncCallback獲取此應用帳號的憑據(jù)的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) = > { 
    console.log("getAccountCredential err: " + JSON.stringify(err));
    console.log('getAccountCredential result: ' + result);
});

getAccountCredential

getAccountCredential(name: string, credentialType: string): Promise

獲取此應用程序帳號的憑據(jù),使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
credentialTypestring要獲取的憑據(jù)的類型。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) = > { 
    console.log('getAccountCredential, result: ' + data);
}).catch((err) = > {
    console.log("getAccountCredential err: "  + JSON.stringify(err));
});

getAccountExtraInfo

getAccountExtraInfo(name: string, callback: AsyncCallback): void

獲取此應用帳號的額外信息,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
callbackAsyncCallback獲取此應用帳號的額外信息的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) = > { 
    console.log("getAccountExtraInfo err: " + JSON.stringify(err));
    console.log('getAccountExtraInfo result: ' + result);
});

getAccountExtraInfo

getAccountExtraInfo(name: string): Promise

獲取此應用程序帳號的額外信息,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAccountExtraInfo("ZhangSan").then((data) = > { 
    console.log('getAccountExtraInfo, result: ' + data);
}).catch((err) = > {
    console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
});

getAssociatedData

getAssociatedData(name: string, key: string, callback: AsyncCallback): void

獲取與此應用程序帳號關聯(lián)的數(shù)據(jù),使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
keystring要獲取的數(shù)據(jù)的key。
callbackAsyncCallback獲取與此應用帳號關聯(lián)的數(shù)據(jù)的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) = > { 
    console.log("getAssociatedData err: " + JSON.stringify(err));
    console.log('getAssociatedData result: ' + result);
});

getAssociatedData

getAssociatedData(name: string, key: string): Promise

獲取與此應用程序帳號關聯(lián)的數(shù)據(jù),使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳號名稱。
keystring要獲取的數(shù)據(jù)的key。

返回值:

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) = > { 
     console.log('getAssociatedData: ' + data);
}).catch((err) = > {
    console.log("getAssociatedData err: "  + JSON.stringify(err));
});

getAllAccessibleAccounts

getAllAccessibleAccounts(callback: AsyncCallback>): void

獲取全部應用已授權帳號信息。

需要權限: ohos.permission.GET_ALL_APP_ACCOUNTS,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
callbackAsyncCallback>應用帳號信息列表

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAllAccessibleAccounts((err, data)= >{
	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
});

getAllAccessibleAccounts

getAllAccessibleAccounts(): Promise>

獲取全部應用已授權帳號信息。

需要權限: ohos.permission.GET_ALL_APP_ACCOUNTS,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

類型說明
Promise>Promise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAllAccessibleAccounts().then((data) = > { 
     console.log('getAllAccessibleAccounts: ' + data);
}).catch((err) = > {
    console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
});

getAllAccounts

getAllAccounts(owner: string, callback: AsyncCallback>): void

獲取指定應用全部帳號信息。

需要權限: ohos.permission.GET_ALL_APP_ACCOUNTS,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
ownerstring應用包名稱
callbackAsyncCallback>應用帳號信息列表

示例:

const appAccountManager = account.createAppAccountManager();
const selfBundle = "com.example.actsgetallaaccounts";
appAccountManager.getAllAccounts(selfBundle, (err, data)= >{
	console.debug("getAllAccounts err:" + JSON.stringify(err));
	console.debug("getAllAccounts data:" + JSON.stringify(data));
});

getAllAccounts

getAllAccounts(owner: string): Promise>

獲取指定應用全部帳號信息。

需要權限: ohos.permission.GET_ALL_APP_ACCOUNTS,僅系統(tǒng)應用可用。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
ownerstring應用包名稱

參數(shù):

類型說明
Promise>Promise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
const selfBundle = "com.example.actsgetallaaccounts";
appAccountManager.getAllAccounts(selfBundle).then((data) = > { 
     console.log('getAllAccounts: ' + data);
}).catch((err) = > {
    console.log("getAllAccounts err: "  + JSON.stringify(err));
});

on('change')

on(type: 'change', owners: Array, callback: Callback>): void

訂閱指定帳號所有者的帳戶變更事件,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
type'change'關于帳戶更改事件,當帳戶所有者更新帳戶時,訂閱者將收到通知。
ownersArray指示帳戶的所有者。
callbackCallback>訂閱指定帳號所有者的帳戶變更事件的回調(diào)。

示例:

const appAccountManager = account.createAppAccountManager();
function changeOnCallback(data){
	console.debug("receive change data:" + JSON.stringify(data));
}
try{
	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
}
catch(err){
	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
}

off('change')

off(type: 'change', callback?: Callback>): void

取消訂閱帳號事件,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
type'change'關于帳戶更改事件。
callbackCallback>取消訂閱帳號事件的回調(diào)。

示例:

const appAccountManager = account.createAppAccountManager();
function changeOnCallback(data){
	console.debug("receive change data:" + JSON.stringify(data));
	appAccountManager.off('change', function(){
		console.debug("off finish");
	})
}
try{
	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
}
catch(err){
	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
}

authenticate8+

authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

鑒權應用帳戶以獲取OAuth令牌,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring要鑒權的應用帳戶的名稱。
ownerstring要鑒權的應用帳戶的所有者包名。
authTypestring鑒權類型。
options{[key: string]: any}鑒權所需的可選項。
callbackAuthenticatorCallback認證器回調(diào),用于返回鑒權結果。

示例:

import featureAbility from '@ohos.ability.featureAbility';

function onResultCallback(code, result) {
    console.log("resultCode: "  + code);
    console.log("result: "  + JSON.stringify(result));
}

function onRequestRedirectedCallback(request) {
    let abilityStartSetting = {want: request};
    featureAbility.startAbility(abilityStartSetting, (err)= >{
        console.log("startAbility err: " + JSON.stringify(err));
    });
}

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "readAge", {}, {
  onResult: onResultCallback,
  onRequestRedirected: onRequestRedirectedCallback
});

getOAuthToken8+

getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback): void

獲取指定應用帳戶和鑒權類型的OAuth令牌,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
authTypestring鑒權類型。
callbackAsyncCallback查詢結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", (err, data) = > {
     console.log('getOAuthToken err: ' + JSON.stringify(err));
     console.log('getOAuthToken token: ' + data);
});

getOAuthToken8+

getOAuthToken(name: string, owner: string, authType: string): Promise

獲取指定應用帳戶和鑒權類型的OAuth令牌,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
authTypestring鑒權類型。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge").then((data) = > {
     console.log('getOAuthToken token: ' + data);
}).catch((err) = > {
    console.log("getOAuthToken err: "  + JSON.stringify(err));
});

setOAuthToken8+

setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback): void

設置指定應用帳戶和鑒權類型的OAuth令牌,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
tokenstringOAuth令牌。
callbackAsyncCallback設置結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx", (err) = > {
    console.log('setOAuthToken err: ' + JSON.stringify(err));
});

setOAuthToken8+

setOAuthToken(name: string, authType: string, token: string): Promise

設置指定應用帳戶和鑒權類型的OAuth令牌,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
tokenstringOAuth令牌。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx").then(() = > {
    console.log('setOAuthToken successfully');
}).catch((err) = > {
    console.log('setOAuthToken err: ' + JSON.stringify(err));
});

deleteOAuthToken8+

deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback): void

刪除指定應用帳戶和鑒權類型的OAuth令牌,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
authTypestring鑒權類型。
tokenstring要刪除的OAuth令牌。
callbackAsyncCallback刪除結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx", (err) = > {
     console.log('deleteOAuthToken err: ' + JSON.stringify(err));
});

deleteOAuthToken8+

deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise

刪除指定應用帳戶和鑒權類型的OAuth令牌,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
authTypestring鑒權類型。
tokenstring要刪除的OAuth令牌。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx").then(() = > {
     console.log('deleteOAuthToken successfully');
}).catch((err) = > {
    console.log("deleteOAuthToken err: "  + JSON.stringify(err));
});

setOAuthTokenVisibility8+

setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback): void

設置指定鑒權類型的OAuth令牌對特定應用的可見性,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
bundleNamestring被設置可見性的應用包名。
isVisibleboolean是否可見。
callbackAsyncCallback設置結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err) = > {
     console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
});

setOAuthTokenVisibility8+

setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise

設置指定鑒權類型的OAuth令牌對特定應用的可見性,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
bundleNamestring被設置可見性的應用包名。
isVisibleboolean是否可見。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then(() = > {
    console.log('setOAuthTokenVisibility successfully');
}).catch((err) = > {
    console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
});

checkOAuthTokenVisibility8+

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback): void

檢查指定鑒權類型的OAuth令牌對特定應用的可見性,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
bundleNamestring用于檢查可見性的應用包名。
callbackAsyncCallback檢查結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err, data) = > {
    console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
    console.log('checkOAuthTokenVisibility isVisible: ' + data);
});

checkOAuthTokenVisibility8+

checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise

檢查指定鑒權類型的OAuth令牌對特定應用的可見性,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
authTypestring鑒權類型。
bundleNamestring用于檢查可見性的應用包名。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then((data) = > {
    console.log('checkOAuthTokenVisibility isVisible: ' + data);
}).catch((err) = > {
    console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
});

getAllOAuthTokens8+

getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback>): void

獲取指定應用對調(diào)用方全部可見的OAuth令牌,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
callbackAsyncCallback>查詢結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) = > {
    console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
    console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
});

getAllOAuthTokens8+

getAllOAuthTokens(name: string, owner: string): Promise>

獲取指定應用帳戶對調(diào)用方可見的全部OAuth令牌,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。

參數(shù):

類型說明
Promise>Promise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) = > {
     console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
}).catch((err) = > {
    console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
});

getOAuthList8+

getOAuthList(name: string, authType: string, callback: AsyncCallback>): void

獲取指定應用帳戶和鑒權類型的OAuth令牌的授權列表,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。
callbackAsyncCallback>查詢結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge", (err, data) = > {
     console.log('getOAuthList err: ' + JSON.stringify(err));
     console.log('getOAuthList data: ' + JSON.stringify(data));
});

getOAuthList8+

getOAuthList(name: string, authType: string): Promise>

獲取指定應用帳戶和鑒權類型的OAuth令牌的授權列表,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
namestring應用帳戶的名稱。
ownerstring應用帳戶的所有者包名。

參數(shù):

類型說明
Promise>Promise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge").then((data) = > {
     console.log('getOAuthList data: ' + JSON.stringify(data));
}).catch((err) = > {
    console.log("getOAuthList err: "  + JSON.stringify(err));
});

getAuthenticatorCallback8+

getAuthenticatorCallback(sessionId: string, callback: AsyncCallback): void

獲取鑒權會話的認證器回調(diào),使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
sessionIdstring鑒權會話的標識。
callbackAsyncCallback查詢結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
featureAbility.getWant((err, want) = > {
  var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
  appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) = > {
      if (err.code != account_appAccount.ResultCode.SUCCESS) {
          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
          return;
      }
      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                    [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
      callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
  });
});

getAuthenticatorCallback8+

getAuthenticatorCallback(sessionId: string): Promise

獲取鑒權會話的認證器回調(diào),使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
sessionIdstring鑒權會話的標識。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
featureAbility.getWant().then((want) = > {
    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
    appAccountManager.getAuthenticatorCallback(sessionId).then((callback) = > {
        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                      [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
    }).catch((err) = > {
        console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
    });
}).catch((err) = > {
    console.log("getWant err: "  + JSON.stringify(err));
});

getAuthenticatorInfo8+

getAuthenticatorInfo(owner: string, callback: AsyncCallback): void

獲取指定應用帳戶的認證器信息,使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
ownerstring應用帳戶的所有者包名。
callbackAsyncCallback查詢結果的回調(diào)。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) = > {
    console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
    console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
});

getAuthenticatorInfo8+

getAuthenticatorInfo(owner: string): Promise

獲取指定應用帳戶的認證器信息,使用Promise方式異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
ownerstring應用帳戶的所有者包名。

參數(shù):

類型說明
PromisePromise實例,用于獲取異步返回結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) = > { 
     console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
}).catch((err) = > {
    console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
});

AppAccountInfo

表示應用帳號信息。

系統(tǒng)能力: 以下各項對應的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

參數(shù)名類型必填說明
ownerstring應用帳戶的所有者包名。
namestring應用帳戶的名稱。

OAuthTokenInfo8+

表示OAuth令牌信息。

系統(tǒng)能力: 以下各項對應的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

參數(shù)名類型必填說明
authTypestring令牌的鑒權類型。
tokenstring令牌的取值。

AuthenticatorInfo8+

表示OAuth認證器信息。

系統(tǒng)能力: 以下各項對應的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

參數(shù)名類型必填說明
ownerstring認證器的所有者包名。
iconIdstring認證器的圖標標識。
labelIdstring認證器的標簽標識。

Constants8+

表示常量的枚舉。

系統(tǒng)能力: 以下各項對應的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

名稱默認值描述
ACTION_ADD_ACCOUNT_IMPLICITLY"addAccountImplicitly"表示操作_隱式添加帳號。
ACTION_AUTHENTICATE"authenticate"表示操作_鑒權。
KEY_NAME"name"表示鍵名_應用帳戶名稱。
KEY_OWNER"owner"表示鍵名_應用帳戶所有者。
KEY_TOKEN"token"表示鍵名_令牌。
KEY_ACTION"action"表示鍵名_操作。
KEY_AUTH_TYPE"authType"表示鍵名_鑒權類型。
KEY_SESSION_ID"sessionId"表示鍵名_會話標識。
KEY_CALLER_PID"callerPid"表示鍵名_調(diào)用方PID。
KEY_CALLER_UID"callerUid"表示鍵名_調(diào)用方UID。
KEY_CALLER_BUNDLE_NAME"callerBundleName"表示鍵名_調(diào)用方包名。

ResultCode8+

表示返回碼的枚舉。

系統(tǒng)能力: 以下各項對應的系統(tǒng)能力均為SystemCapability.Account.AppAccount。

名稱默認值描述
SUCCESS0表示操作成功。
ERROR_ACCOUNT_NOT_EXIST10001表示應用帳戶不存在。
ERROR_APP_ACCOUNT_SERVICE_EXCEPTION10002表示應用帳戶服務異常。
ERROR_INVALID_PASSWORD10003表示密碼無效。
ERROR_INVALID_REQUEST10004表示請求無效。
ERROR_INVALID_RESPONSE10005表示響應無效。
ERROR_NETWORK_EXCEPTION10006表示網(wǎng)絡異常。
ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST10007表示認證器不存在。
ERROR_OAUTH_CANCELED10008表示鑒權取消。
ERROR_OAUTH_LIST_TOO_LARGE10009表示開放授權列表過大。
ERROR_OAUTH_SERVICE_BUSY10010表示開放授權服務忙碌。
ERROR_OAUTH_SERVICE_EXCEPTION10011表示開放授權服務異常。
ERROR_OAUTH_SESSION_NOT_EXIST10012表示鑒權會話不存在。
ERROR_OAUTH_TIMEOUT10013表示鑒權超時。
ERROR_OAUTH_TOKEN_NOT_EXIST10014表示開放授權令牌不存在。
ERROR_OAUTH_TOKEN_TOO_MANY10015表示開放授權令牌過多。
ERROR_OAUTH_UNSUPPORT_ACTION10016表示不支持的鑒權操作。
ERROR_OAUTH_UNSUPPORT_AUTH_TYPE10017表示不支持的鑒權類型。
ERROR_PERMISSION_DENIED10018表示權限不足。

AuthenticatorCallback8+

OAuth認證器回調(diào)接口。

onResult8+

onResult: (code: number, result: {[key: string]: any}) => void

通知鑒權結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
codenumber鑒權結果碼。
result{[key: string]: any}鑒權結果。

示例:

const appAccountManager = account_appAccount.createAppAccountManager();
var sessionId = "1234";
appAccountManager.getAuthenticatorCallback(sessionId).then((callback) = > {
    var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                  [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                  [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                  [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
    callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
}).catch((err) = > {
    console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
});

onRequestRedirected8+

onRequestRedirected: (request: Want) => void

通知鑒權請求被跳轉。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
requestWant用于跳轉的請求信息。

示例:

class MyAuthenticator extends account_appAccount.Authenticator {
    addAccountImplicitly(authType, callerBundleName, options, callback) {
        callback.onRequestRedirected({
            bundleName: "com.example.ohos.accountjsdemo",
            abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
        });
    }

    authenticate(name, authType, callerBundleName, options, callback) {
        var result = {[account_appAccount.Constants.KEY_NAME]: name,
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
}

Authenticator8+

OAuth認證器基類。

addAccountImplicitly8+

addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

根據(jù)指定的鑒權類型和可選項,隱式地添加應用帳戶,并使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

參數(shù)名類型必填說明
authTypestring應用帳戶的鑒權類型。
callerBundleNamestring鑒權請求方的包名。
options{[key: string]: any}鑒權所需要的可選項。
callbackAuthenticatorCallback認證器回調(diào),用于返回鑒權結果。

authenticate8+

authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void

對應用帳戶進行鑒權,獲取OAuth令牌,并使用callback回調(diào)異步返回結果。

系統(tǒng)能力: SystemCapability.Account.AppAccount

參數(shù):

QQ截圖20240705210937.png

接口名類型必填說明HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
namestring應用帳戶的名稱。
authTypestring應用帳戶的鑒權類型。
callerBundleNamestring鑒權請求方的包名。
options{[key: string]: any}鑒權所需要的可選項。
callbackAuthenticatorCallback認證器回調(diào),用于返回鑒權結果。

示例:

class MyAuthenticator extends account_appAccount.Authenticator {
    addAccountImplicitly(authType, callerBundleName, options, callback) {
        callback.onRequestRedirected({
            bundleName: "com.example.ohos.accountjsdemo",
            abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
        });
    }

    authenticate(name, authType, callerBundleName, options, callback) {
        var result = {[account_appAccount.Constants.KEY_NAME]: name,
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
    }
}

export default {
    onConnect(want) {
        return new MyAuthenticator();
    }
}

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 設備管理
    +關注

    關注

    0

    文章

    105

    瀏覽量

    9266
  • 鴻蒙
    +關注

    關注

    57

    文章

    2295

    瀏覽量

    42638
收藏 人收藏

    評論

    相關推薦

    設備管理系統(tǒng)軟件有哪些

    設備管理系統(tǒng)軟件有哪些,下面是 設備管理軟件功能摘要的NLP顏色標記版,歡迎對比查看素版設備管理軟件功能摘要,有想法反映留言,謝謝~~預測\color{#D2691E}預測預測性\color
    發(fā)表于 07-12 07:01

    設備管理應用程序

    設備管理應用程序,預測性的設備管理軟件 企業(yè)要求對他們的設施在成本效益和環(huán)境影響等方面進行更嚴格的管理。集成所有設備,環(huán)保設施,使用跟蹤,能耗監(jiān)測的信息,并將信息以形象的方式有效的
    發(fā)表于 07-12 07:47

    基于.Net框架的設備管理系統(tǒng)的設計與實現(xiàn)

    設備管理系統(tǒng)是企業(yè)運營過程中必不可少的組成部分。本文以中國教育經(jīng)濟信息網(wǎng)管理中心設備管理系統(tǒng)為例,討論了設備管理系統(tǒng)的設計與實現(xiàn),并詳細討論了基于.Net框架的三
    發(fā)表于 08-28 09:02 ?28次下載

    設備管理云平臺是什么?有什么功能?

    設備管理云平臺:現(xiàn)代化企業(yè)的重要解決方案 隨著科技的迅速發(fā)展和企業(yè)規(guī)模的擴大,設備數(shù)量和種類也隨之增加,設備管理變得愈加復雜。傳統(tǒng)的管理方法已經(jīng)無法滿足企業(yè)的需求,而
    的頭像 發(fā)表于 09-20 16:39 ?1350次閱讀

    基于RFID油井設備管理手持機的開發(fā)研究

    電子發(fā)燒友網(wǎng)站提供《基于RFID油井設備管理手持機的開發(fā)研究.pdf》資料免費下載
    發(fā)表于 10-23 09:35 ?0次下載
    基于RFID油井<b class='flag-5'>設備管理</b>手持機的<b class='flag-5'>開發(fā)</b>研究

    HarmonyOS開發(fā)實例:【app帳號管理

    本示例選擇應用進行注冊/登錄,并設置帳號相關信息,簡要說明應用帳號管理相關功能。
    的頭像 發(fā)表于 04-14 09:46 ?352次閱讀
    HarmonyOS<b class='flag-5'>開發(fā)</b>實例:【app<b class='flag-5'>帳號</b><b class='flag-5'>管理</b>】

    鴻蒙開發(fā)接口定制管理:【@ohos.enterpriseDeviceManager (企業(yè)設備管理)】

    以異步方法根據(jù)給定的包名和類名激活設備管理員應用,使用Callback形式返回是否激活成功。
    的頭像 發(fā)表于 06-05 09:24 ?461次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b>接口定制<b class='flag-5'>管理</b>:【@<b class='flag-5'>ohos</b>.enterpriseDeviceManager (企業(yè)<b class='flag-5'>設備管理</b>)】

    鴻蒙開發(fā)設備管理ohos.multimodalInput.inputDevice 輸入設備

    輸入設備管理模塊,用于監(jiān)聽輸入設備連接、斷開和變化,并查看輸入設備相關信息。比如監(jiān)聽鼠標插拔,并獲取鼠標的id、name和指針移動速度等信息。
    的頭像 發(fā)表于 07-01 09:19 ?288次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>設備管理</b>:<b class='flag-5'>ohos</b>.multimodalInput.inputDevice 輸入<b class='flag-5'>設備</b>

    鴻蒙開發(fā)設備管理ohos.thermal 熱管理

    該模塊提供熱管理相關的接口,包括熱檔位查詢及注冊回調(diào)等功能。
    的頭像 發(fā)表于 07-05 09:53 ?234次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>設備管理</b>:<b class='flag-5'>ohos</b>.thermal 熱<b class='flag-5'>管理</b>

    鴻蒙開發(fā)設備管理ohos.usb USB管理

    本模塊主要提供管理USB設備的相關功能,包括查詢USB設備列表、批量數(shù)據(jù)傳輸、控制命令傳輸、權限控制等。
    的頭像 發(fā)表于 07-05 17:34 ?520次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>設備管理</b>:<b class='flag-5'>ohos</b>.usb USB<b class='flag-5'>管理</b>

    鴻蒙開發(fā)管理ohos.account.distributedAccount 分布式帳號管理

    獲取分布式帳號單實例對象。
    的頭像 發(fā)表于 07-08 10:03 ?192次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>管理</b>:<b class='flag-5'>ohos.account</b>.distributedAccount 分布式<b class='flag-5'>帳號</b><b class='flag-5'>管理</b>

    鴻蒙開發(fā)管理ohos.account.osAccount 系統(tǒng)帳號管理

    本模塊提供管理系統(tǒng)帳號的一些基礎能力,包括系統(tǒng)帳號的添加、刪除、查詢、設置、訂閱、啟動等功能,提供系統(tǒng)帳號數(shù)據(jù)落盤的能力。
    的頭像 發(fā)表于 07-08 09:54 ?267次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>管理</b>:<b class='flag-5'>ohos.account</b>.osAccount 系統(tǒng)<b class='flag-5'>帳號</b><b class='flag-5'>管理</b>

    設備管理系統(tǒng):是什么、誰需要、推薦設備管理系統(tǒng)

    設備管理系統(tǒng)(EMS)在企業(yè)管理中愈發(fā)重要。中設智控設備管理系統(tǒng)以全生命周期管理為主,涵蓋預算、采購、維護等功能,支持移動端應用,降低備件儲備,提高
    的頭像 發(fā)表于 08-01 11:23 ?388次閱讀
    <b class='flag-5'>設備管理</b>系統(tǒng):是什么、誰需要、推薦<b class='flag-5'>設備管理</b>系統(tǒng)

    設備管理流程優(yōu)化的優(yōu)勢

    設備管理對企業(yè)生產(chǎn)效率、產(chǎn)品質(zhì)量、成本控制和安全生產(chǎn)起著關鍵作用。但設備管理面臨挑戰(zhàn),如種類繁多、數(shù)量龐大、位置分散等。因此,企業(yè)應采用科學的設備管理方法,建立設備管理系統(tǒng),跟蹤
    的頭像 發(fā)表于 09-05 10:34 ?211次閱讀
    <b class='flag-5'>設備管理</b>流程優(yōu)化的優(yōu)勢

    基于物聯(lián)網(wǎng)的設備管理

    物聯(lián)網(wǎng)設備管理的重要性日益凸顯,設備數(shù)量激增帶來數(shù)據(jù)泄露風險。加強設備安全性、軟件升級與修復、身份驗證和互操作性是關鍵。物聯(lián)網(wǎng)設備管理需要跨異構設備
    的頭像 發(fā)表于 09-10 11:04 ?551次閱讀
    基于物聯(lián)網(wǎng)的<b class='flag-5'>設備管理</b>