一个迟到的回答,我知道,但我希望这会帮助别人:
MYSITE可以像thunderofthor.com
第1步:
设置2 OAuth认证的感兴趣的App Engine域名。为此,请以管理员身份登录到https://www.google.com/a/MYSITE。在高级工具下,点击管理OAuth域密钥。在这里,点击“启用此使用者密钥”和“允许访问所有API”以启用这些选项。在Google方面,您现在可以处理使用消费者密钥和OAUTHCONSUMERSECRET的请求。
第2步:
在你的servlet代码,你可以确认客户端通过请求OAuthConsumerKey正确的凭据,这将是MYSITE
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String user = null;
try {
OAuthService oauth = OAuthServiceFactory.getOAuthService();
user = oauth.getOAuthConsumerKey();
LOG.info("Authenticated: " + user);
} catch (OAuthRequestException e) {
LOG.info("Not authenticated: " + e.getMessage());
}
第3步:
下载来自Google的GTMOAuth包。它将允许iOS轻松地与您的服务器通话。您不需要整个软件包进行双脚认证。事实上,你需要的只是GTMOAuthAuthentication文件。要在您的代码中使用,请执行以下操作:
NSURL *url = [NSURL URLWithString:@"https://MYSITE/dosomething"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 consumerKey:@"MYSITE" privateKey:@"OAUTHCONSUMERSECRET"] ;
[auth setVersion:@"1.0"];
[auth addRequestTokenHeaderToRequest:request];
// Perform request and get JSON back as a NSData object
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
There!无需用户名和密码即可轻松进行安全通信!