iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine

标签 iphone ios google-app-engine oauth google-toolbox-for-mac

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

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

    - (id)initWithScope:(NSString *)scope
        language:(NSString *)language
  appServiceName:(NSString *)keychainAppServiceName
        delegate:(id)delegate 
finishedSelector:(SEL)finishedSelector;

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

提前致谢!

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

最佳答案

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

MYSITE 可以是类似 Thunderofthor.com

第 1 步:

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

第 2 步:

在您的 servlet 代码中,您可以通过请求 OAuthConsumerKey 来确认客户端具有正确的凭据,该 key 将为 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 步:

下载GTMOAuth来自谷歌的包。它将允许 iOS 轻松地与您的服务器通信。您不需要整个包来进行 2 足身份验证。事实上,您所需要的只是 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/

相关文章:

iphone - 应用拒绝 : Google Analytics ios sdk 2. 0

objective-c - 如何将此 subview 推送到它自己的子类中?

java - 使用 GAE 搜索 API 限制结果

iphone - 使用 objective-c 将文件从应用程序上传到服务器

ios - handleWatchKitExtensionRequest 在 iPhone 上播放背景音频

python - 如何访问用于在 Google App Engine for python 中存储数据的低级 API

java - Android 存储数据的策略

iphone - 使用模式过滤数组

iPhone 矩阵乘法和求逆

iphone - UITableView : error after connected table view to datasource