Nic*_*ton 3 authentication cookies google-app-engine android token
我有一个Android应用程序,我想连接到基于Google App Engine的服务器.我可以从AccountManager获取身份验证令牌.看来我接下来要做的就是与auth页面交谈以获取cookie.遵循这里的精彩指示:http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app 我认为我的网址应该是:
https://MYAPP.appspot.com/_ah/login?continue=http://localhost/&auth=CrAZYl000ngToken
Run Code Online (Sandbox Code Playgroud)
但我没有重定向,而是出现500服务器错误:
Error: Server Error
The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message
and the query that caused it.
Run Code Online (Sandbox Code Playgroud)
那是怎么回事?我应该去的URL是什么?或者我可能做错了什么?
好的,毕竟URL没有错.问题是令牌已过期.我能够通过无效和重新获取令牌来解决这个问题.
private class GetAuthTokenTask extends AsyncTask<Account, Object, String> {
@Override
protected String doInBackground(Account... accounts) {
AccountManager manager = AccountManager.get(getApplicationContext());
Account account = accounts[0];
String token = this.buildToken(manager, account);
manager.invalidateAuthToken(account.type, token);
return this.buildToken(manager, account);
}
private String buildToken(AccountManager manager, Account account) {
try {
AccountManagerFuture<Bundle> future = manager.getAuthToken (account, "ah", false, null, null);
Bundle bundle = future.getResult();
return bundle.getString(AccountManager.KEY_AUTHTOKEN);
} catch (OperationCanceledException e) {
Log.w(TAG, e.getMessage());
} catch (AuthenticatorException e) {
Log.w(TAG, e.getMessage());
} catch (IOException e) {
Log.w(TAG, e.getMessage());
}
return null;
}
protected void onPostExecute(String authToken) {
new GetCookieTask().execute(authToken);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2531 次 |
| 最近记录: |