我在我的應用程序中使用雲計算進行推送通知。我在客戶端身份驗證令牌中遇到問題。我使用以下用於驗證客戶端登錄令牌雲計算中用於應用程序引擎客戶端的哪個URL?
public class AppEngineClient {
private static final String TAG = "AppEngineClient";
public static final String BASE_URL = " <Don't know which URL to use here>";
public static final String AUTH_URL = BASE_URL + "/_ah/login";
public static final String AUTH_TOKEN_TYPE = "ah";
public final Context mContext;
public final String mAccountName;
public AppEngineClient(Context context, String accountName) {
this.mContext = context;
this.mAccountName = accountName;
}
public HttpResponse makeRequest(String urlPath, List<NameValuePair> params) throws Exception {
HttpResponse res = makeRequestNoRetry(urlPath, params, false);
if (res.getStatusLine().getStatusCode() == 500) {
res = makeRequestNoRetry(urlPath, params, true);
}
return res;
}
public HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken)
throws Exception {
// Get auth token for account
Account account = new Account(mAccountName, "com.google");
String authToken = getAuthToken(mContext, account);
if (authToken == null) throw new PendingAuthException(mAccountName);
if (newToken) { // invalidate the cached token
AccountManager accountManager = AccountManager.get(mContext);
accountManager.invalidateAuthToken(account.type, authToken);
authToken = getAuthToken(mContext, account);
}
// Get ACSID cookie
DefaultHttpClient client = new DefaultHttpClient();
String continueURL = BASE_URL;
URI uri = new URI(AUTH_URL + "?continue=" +
URLEncoder.encode(continueURL, "UTF-8") +
"&auth=" + authToken);
HttpGet method = new HttpGet(uri);
final HttpParams getParams = new BasicHttpParams();
HttpClientParams.setRedirecting(getParams, false); // continue is not used
method.setParams(getParams);
HttpResponse res = client.execute(method);
Header[] headers = res.getHeaders("Set-Cookie");
if (res.getStatusLine().getStatusCode() != 302 ||
headers.length == 0) {
return res;
}
String ascidCookie = null;
for (Header header: headers) {
if (header.getValue().indexOf("ACSID=") >=0) {
// let's parse it
String value = header.getValue();
String[] pairs = value.split(";");
ascidCookie = pairs[0];
}
}
// Make POST request
uri = new URI(BASE_URL + urlPath);
HttpPost post = new HttpPost(uri);
UrlEncodedFormEntity entity =
new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
post.setHeader("Cookie", ascidCookie);
post.setHeader("X-Same-Domain", "1"); // XSRF
res = client.execute(post);
return res;
}
public String getAuthToken(Context context, Account account) {
String authToken = null;
AccountManager accountManager = AccountManager.get(context);
try {
AccountManagerFuture<Bundle> future =
accountManager.getAuthToken (account, AUTH_TOKEN_TYPE, false, null, null);
Bundle bundle = future.getResult();
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
// User will be asked for "App Engine" permission.
if (authToken == null) {
// No auth token - will need to ask permission from user.
Intent intent = new Intent("com.google.ctp.AUTH_PERMISSION");
intent.putExtra("AccountManagerBundle", bundle);
context.sendBroadcast(intent);
}
} 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 authToken;
}
public class PendingAuthException extends Exception {
private static final long serialVersionUID = 1L;
public PendingAuthException(String message) {
super(message);
}
}
}
這是我通過瀏覽器使用用戶認證通過應用程序引擎的客戶打電話例如雲計算的類,但在使用這個類,我不明白這BASE_URL,我必須在這堂課中給予。請告訴我,如果URL來自服務器端,應使用哪個URL以及在服務器端要做什麼。
在此先感謝
如果有人知道這件事,然後plzzzz幫我出我的問題 – Nikki 2011-03-30 04:15:46
@CommonsWare的:你好先生..你一直都很棒,你可以幫我解決這個問題。 – Nikki 2011-03-30 05:53:55
因爲沒有引起太多注意,所以不允許標記你的問題。如果你想引起人們對你的問題的關注,那麼兩天後你將被允許[放置賞金](http://stackoverflow.com/faq#bounty)。你也可以[編輯你的問題](http://stackoverflow.com/posts/5472819/edit)添加額外的信息,這可能會讓你的問題更容易理解和回答。 – Will 2011-04-04 13:33:04