OGeek|极客世界-中国程序员成长平台

标题: iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:56
标题: iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine

我正在尝试使用 OAuth 将 iOS 应用程序与 Google App Engine 集成。我发现 GTM 有一个 OAuth Controller -- http://code.google.com/p/gtm-oauth/

可以用来连接 Google App Engine 吗?如果是这样,我将什么作为“范围”参数放入

    - (id)initWithScopeNSString *)scope
        languageNSString *)language
  appServiceNameNSString *)keychainAppServiceName
        delegateid)delegate 
finishedSelectorSEL)finishedSelector;

我尝试使用我的 App Engine 应用程序的地址 (http://my-app-name.appspot.com),但没有成功。

提前致谢!

顺便说一句,这是对 Authenticating into Google App Engine from an iOS device 的后续问题。 .



Best Answer-推荐答案


我知道一个较晚的答案,但希望这会对某人有所帮助:

MYSITE 可以是 Thunderofthor.com 之类的网站

第 1 步:

为感兴趣的 App Engine 域设置 2-legged OAuth。为此,请以管理员身份登录 https://www.google.com/a/MYSITE .在高级工具下,单击管理 OAuth 域 key 。在这里,单击“启用此使用者 key ”和“允许访问所有 API”以启用这些选项。在 Google 方面,您现在可以处理使用 MYSITE 消费者 key 和 OAUTHCONSUMERSECRET 的请求。

第 2 步:

在您的 servlet 代码中,您可以通过请求 MYSITE

的 OAuthConsumerKey 来确认客户端具有正确的凭据
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 步:

下载GTMOAuth来自谷歌的包。它将允许 iOS 毫不费力地与您的服务器通信。 2-legged auth 不需要整个软件包。事实上,您所需要的只是 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];

那里!无需用户名和密码即可轻松进行安全通信!

关于iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6183313/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4