从基于 GAE 的应用程序获取身份验证 Cookie 的正确 URL 是什么

发布于 2024-09-27 08:10:43 字数 766 浏览 2 评论 0原文

我有一个 Android 应用程序,我想连接到基于 Google App Engine 的服务器。我可以从 AccountManager 获取身份验证令牌。看来我接下来要做的就是与身份验证页面对话以获取 cookie。按照此处的精彩说明进行操作: http:// /blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app 我认为我的 url 应该是:

https://MYAPP.appspot.com/_ah/login?continue=http://localhost/&auth=CrAZYl000ngToken

但我收到的不是重定向,而是 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.

这是怎么回事?我应该访问的 URL 是什么?或者也许我做错了什么?

I have an android app I want to connect to a Google App Engine based server. I can get the auth token from the AccountManager. It seems the next thing I am supposed to do is talk to an auth page to get a cookie. Following the awesome instructions here: http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app
I think my url should be:

https://MYAPP.appspot.com/_ah/login?continue=http://localhost/&auth=CrAZYl000ngToken

but rather than a redirect, I get a 500 server error:

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.

What's up with that? What is the URL I am supposed to be going to? Or maybe I'm doing something else wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦中楼上月下 2024-10-04 08:10:43

好吧,网址毕竟没有错。问题是令牌已过期。我能够通过使令牌失效并重新获取令牌来解决这个问题。

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);    
    }
}

OK, the URL wasn't wrong after all. The problem was that the token was expired. I was able to solve this by invalidating and re-fetching the token.

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);    
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文