harmony 鸿蒙Authenticating a Domain Account (for System Applications Only)
Authenticating a Domain Account (for System Applications Only)
Authenticate a domain account before unlocking the screen or when the login session fails.
Before You Start
Import the osAccount module.
import { osAccount } from '@kit.BasicServicesKit';
Domain Account Authentication by Password
The domain account can be authenticated by password. You can use auth to implement this operation. To call this API, the application must have the ohos.permission.ACCESS_USER_AUTH_INTERNAL permission.
Procedure
Request the ohos.permission.ACCESS_USER_AUTH_INTERNAL permission. For details, see Requesting Permissions for system_basic Applications.
Obtain user input information, including the domain account and its password.
let domainAccountInfo: osAccount.DomainAccountInfo = {
domain: 'CHINA',
accountName: 'zhangsan'
}
let credential: Uint8Array = new Uint8Array([0]);
- Define the callback used to return the authentication result.
let callback: osAccount.IUserAuthCallback = {
onResult: (resultCode: number, authResult: osAccount.AuthResult) => {
console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult));
}
}
- Use auth to authenticate the domain account by password.
try {
osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback);
} catch (err) {
console.log('auth exception = ' + JSON.stringify(err));
}
Domain Account Authentication by Dialog
If the domain account password is unavailable, display a dialog box to authentication the domain account. You can use authWithPopup to implement this operation.
Procedure
- Define the callback used to return the authentication result.
let callback: osAccount.IUserAuthCallback = {
onResult: (resultCode: number, authResult: osAccount.AuthResult) => {
console.log('authWithPopup resultCode = ' + resultCode);
console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
}
}
- Use authWithPopup to authenticate the domain account in a dialog box displayed.
try {
osAccount.DomainAccountManager.authWithPopup(callback)
} catch (err) {
console.log('authWithPopup exception = ' + JSON.stringify(err));
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Account Management Overview
harmony 鸿蒙Applying Constraints for System Accounts
harmony 鸿蒙Managing Application Accounts
harmony 鸿蒙Managing Distributed Accounts (for System Applications Only)
harmony 鸿蒙Managing Domain Accounts (for System Applications Only)
harmony 鸿蒙Managing Domain Account Plugins (for System Applications Only)
harmony 鸿蒙Managing System Account Credentials (for System Application Only)
harmony 鸿蒙Managing System Accounts (for System Applications Only)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦