Microsoft 身份验证库 (MSAL) 永远不会从 Android 上的 AcquireTokenAsync() 返回
我在我的 Android 应用程序中使用 Microsoft Azure 登录和 Microsoft 身份验证库 (MSAL)。登录在两个应用程序上都可以正常工作(调试和签名),但是在将应用程序上传到 Play 商店后,Microsoft Azure 登录页面无法打开。在Play商店上传应用程序后我无法登录。
===========Step 1===============
PublicClientApplication.createSingleAccountPublicClientApplication(
this,
R.raw.auth_config_hcl,
// R.raw.auth_config,
object : ISingleAccountApplicationCreatedListener {
override fun onCreated(iSingleAccountPublicClientApplication:
ISingleAccountPublicClientApplication) {
this@MainActivity.mSingleAccountApp = iSingleAccountPublicClientApplication
this@MainActivity.loadAccount()
// loadingShow()
}
override fun onError(msalException: MsalException) {
if(BuildConfig.DEBUG) {
Logger.debug(msg = msalException.errorCode)
msalException.printStackTrace()
}
signShow()
}
})
===========Step 2===============
val iSingleAccountPublicClientApplication =
mSingleAccountApp
iSingleAccountPublicClientApplication?.getCurrentAccountAsync(object :
CurrentAccountCallback {
override fun onAccountChanged(iAccount: IAccount?, iAccount2: IAccount?) {}
override fun onAccountLoaded(iAccount: IAccount?) {
iAccount?.run {
loadingShow()
SharedPrefencesUtil.getInstance(this@MainActivity)?.saveData(username)
callApi()
}
}
override fun onError(msalException: MsalException) {
showToast(getString(R.string.error))
signShow()
}
})
===========Step 3===============
mSingleAccountApp?.run {
signIn(this@MainActivity, CommonWord.Empty, getScopes(), object :
AuthenticationCallback {
override fun onSuccess(authenticationResult: IAuthenticationResult?) {
if (authenticationResult == null){
signShow()
return
}
authenticationResult.run(::callGraphAPI)
}
override fun onCancel() {
showToast(getString(R.string.cancel))
signShow()
}
override fun onError(exception: MsalException?) {
showToast(getString(R.string.error))
signShow()
}
})
}
===========Config File================
"client_id": “<client_id>”,
"authorization_user_agent": "DEFAULT",
"account_mode": "SINGLE",
"redirect_uri": "msauth://com.hcl.HumanErrorAvoidance/<hask_key>“,
"authorities": [
{
"type": "AAD",
"authority_url": "https://login.microsoftonline.com/<id>“,
"audience": {
"type": "AzureADMyOrg",
"tenant_id": “<tenant_id>“
}
}
]
}