• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 07:56:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试使用 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap