gpt4 book ai didi

安卓 Bootstrap : Need to pass the authToken to my request accept header

转载 作者:行者123 更新时间:2023-11-29 18:04:53 24 4
gpt4 key购买 nike

好吧,我一直在努力理解这个"template"的身份验证过程 project就是不明白。

我想做的是基本登录,这样我就可以获得我的授权 token ,我之前通过使用 SharedPreference(从未实际使用过 AccountManager)并从我的其余 Android 客户端访问它(通过自定义 session 管理器)。

到目前为止,我已经完成了第一部分。我可以获得我的授权 token 。

BoostrapAuthenticatorActivity.java:

 /**
* Called when response is received from the server for authentication
* request. See onAuthenticationResult(). Sets the
* AccountAuthenticatorResult which is sent back to the caller. Also sets
* the authToken in AccountManager for this account.
*/

protected void finishLogin() {
final Account account = new Account(email, Constants.Auth.LZGO_ACCOUNT_TYPE);

if (requestNewAccount)
accountManager.addAccountExplicitly(account, password, null);
else
accountManager.setPassword(account, password);
final Intent intent = new Intent();
authToken = token;
userToken = user;
intent.putExtra(KEY_ACCOUNT_NAME, userToken);
intent.putExtra(KEY_ACCOUNT_TYPE, Constants.Auth.LZGO_ACCOUNT_TYPE);
if (authTokenType != null
&& authTokenType.equals(Constants.Auth.AUTHTOKEN_TYPE))
intent.putExtra(KEY_AUTHTOKEN, authToken);
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK, intent);
finish();
}

我如何访问这个值?如果你检查这个类,

BootstrapServiceProvider.java:

@Inject private ApiKeyProvider keyProvider;
@Inject private UserAgentProvider userAgentProvider;

/**
* Get service for configured key provider
* <p>
* This method gets an auth key and so it blocks and shouldn't be called on the main thread.
*
* @return bootstrap service
* @throws IOException
* @throws AccountsException
*/
public BootstrapService getService() throws IOException, AccountsException {
return new BootstrapService(keyProvider.getAuthKey(), userAgentProvider);
}

最后,提供者:

ApiKeyProvider.java:

@Inject private Activity activity;
@Inject private AccountManager accountManager;

/**
* This call blocks, so shouldn't be called on the UI thread
*
* @return API key to be used for authorization with a {@link com.android.lzgo.core.LzgoService} instance
* @throws AccountsException
* @throws IOException
*/
public String getAuthKey() throws AccountsException, IOException {
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthTokenByFeatures(Constants.Auth.BOOTSTRAP_ACCOUNT_TYPE,
Constants.Auth.AUTHTOKEN_TYPE, new String[0], activity, null, null, null, null);
Log.d("ApiKeyProvider", "ApiKeyProvider= " + accountManagerFuture.getResult().getString(KEY_AUTHTOKEN));
return accountManagerFuture.getResult().getString(KEY_AUTHTOKEN);
}

但这让我得到了一个空值!我迷路了!

最佳答案

我不确定为什么 setAccountAuthenticatorResult(...) 没有正确应用 authtoken,但是我很幸运地添加了以下 accountManager.setAuthToken(。 ..) 调用 finishLogin()

if (authTokenType != null
&& authTokenType.equals(Constants.Auth.AUTHTOKEN_TYPE)) {
intent.putExtra(KEY_AUTHTOKEN, authToken);
accountManager.setAuthToken(account, authTokenType, authToken);
}

也许这与不使用 Parse.com 作为我们的后端有关?

关于安卓 Bootstrap : Need to pass the authToken to my request accept header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13921283/

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