gpt4 book ai didi

java - 尝试从 Android 应用程序获取 TokenSilentAsync

转载 作者:行者123 更新时间:2023-12-01 14:31:38 26 4
gpt4 key购买 nike

我正在使用

implementation 'com.microsoft.identity.client:msal:1.4.0'

为了通过 azure 连接到应用程序,我的 acquireToken() 工作正常并且我得到了用户响应(我将其保存在 SharedPrefs 中)

在那之后(下次登录)我尝试像这样执行 acquireTokenSilentAsync :

      SharedPreferences pref = getSharedPreferences();

Gson gson = new Gson();
String json = pref.getString("IAccount", "");


if(!json.isEmpty()){
Account account = gson.fromJson(json, Account.class);
AcquireTokenSilentParameters parameters = new AcquireTokenSilentParameters.Builder()
.withScopes(Arrays.asList(scopes))
.forAccount(account)
.fromAuthority(getAuthority())
.withCallback(getSilentAuthInteractiveCallback())
.build();
application.acquireTokenSilentAsync(parameters);
}

然后进入 onError 回调,除了:

>  E/onError: exception : com.microsoft.identity.client.Account cannot be cast to com.microsoft.identity.client.MultiTenantAccount

有什么遗漏的想法吗?

非常感谢。

最佳答案

此页面可能有帮助:

https://learn.microsoft.com/en-us/azure/active-directory/develop/accounts-overview

特别是,他们不使用 Gson,他们强制转换帐户以防止您在他们的示例代码中遇到异常。

我会先尝试像这样转换:

IMultiTenantAccount multiTenantAccount = (IMultiTenantAccount)account;

并将其用作 forAccount() 中的参数。

关于java - 尝试从 Android 应用程序获取 TokenSilentAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com