【问题标题】:MSAL for Android: SHA-256 digest error (AuthenticationCallback.class) during Instant Run with androidx适用于 Android 的 MSAL:使用 androidx 即时运行期间的 SHA-256 摘要错误 (AuthenticationCallback.class)
【发布时间】:2019-05-04 02:45:22
【问题描述】:

有没有办法让 MSAL 与 Instant Run 和 AndroidX 一起工作?

Microsoft Authentication Library 0.2.1 开箱即用地与 Android Studio 配合使用,但在启用 Instant Run 后迁移到 androidx 后会出现构建错误。

编译时Java编译器报如下错误:

java.lang.SecurityException:com/microsoft/identity/client/AuthenticationCallback.class 的 SHA-256 摘要错误

复制:

  1. 创建一个新的 Android Studio 项目
  2. 确保已启用即时运行(文件 > 设置 > 构建、执行、部署 > 即时运行)
  3. 按照此处的说明进行操作:https://github.com/AzureAD/microsoft-authentication-library-for-android
  4. 调试。一切都会好起来的。
  5. 将以下内容添加到 gradle.properties:
    • android.useAndroidX=true
    • android.enableJetifier=true
  6. 重构 > 迁移到 AndroidX(无关:如果需要修复布局等)
  7. 尝试开始调试
  8. 现在编译器会报告上述错误
  9. 禁用即时运行
  10. 调试
  11. 现在一切正常。

我的 MainActivity 如下所示:

class MainActivity : AppCompatActivity() {

val CLIENT_ID = "<My Client Id>"
val SCOPES = arrayOf("https://graph.microsoft.com/User.Read")
private lateinit var sampleApp: PublicClientApplication

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    sampleApp = PublicClientApplication(
        this.applicationContext,
        CLIENT_ID
    )
    sampleApp.acquireToken(this, SCOPES, getAuthInteractiveCallback());
}

private fun getAuthInteractiveCallback(): AuthenticationCallback {
    return object : AuthenticationCallback {
        override fun onSuccess(authenticationResult: AuthenticationResult) {
            val accessToken = authenticationResult.getAccessToken()
        }
        override fun onError(exception: MsalException) {
            if (exception is MsalClientException) {
                /* Exception inside MSAL, more info inside MsalError.java */
            } else if (exception is MsalServiceException) {
                /* Exception when communicating with the STS, likely config issue */
            }
        }
        override fun onCancel() {
            /* User canceled the authentication */
        }
    }
}

/* Handles the redirect from the System Browser */
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    sampleApp.handleInteractiveRequestRedirect(requestCode, resultCode, data)
}
}

编辑:GitHub 问题https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/354

【问题讨论】:

  • 如 Github 上所述,这是一个已知问题,但产品团队尚未对其进行分类。

标签: android msal androidx android-instant-run


【解决方案1】:

现在似乎可以使用(不知道它何时修复或如何修复,但 MSAL 0.2.2 和 0.3.1-alpha 似乎都适用于 2019 年 4 月 10 日版本的 Android Studio)。

【讨论】:

    【解决方案2】:

    我正在我的 Android 应用程序中集成 AD 登录,当我启用 Instant Run 时,我开始遇到这个问题。所以我再次禁用 Instant Run,现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-12
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2015-06-18
      • 2012-12-31
      相关资源
      最近更新 更多