使用 Google Toolbox for Mac OAuth for Google App Engine

发布于 2024-11-10 17:44:54 字数 807 浏览 4 评论 0原文

我正在尝试使用 OAuth 将 iOS 应用程序与 Google App Engine 集成。我发现 GTM 有一个 OAuth 控制器 - 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的后续问题来自 iOS 设备的引擎

I am trying to integrate an iOS application with Google App Engine using OAuth. I found that GTM has an OAuth Controller -- http://code.google.com/p/gtm-oauth/

Can it be used to connect to Google App Engine? If so, what do I put as the "scope" parameter in

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

I've tried to use my App Engine application's address (http://my-app-name.appspot.com) but it didn't work.

Thanks in advance!

btw this is sort of a follow up question to Authenticating into Google App Engine from an iOS device.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2024-11-17 17:44:54

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

MYSITE 可以是类似 Thunderofthor.com 的内容

步骤 1:

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

步:

在您的 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());
}

第2

。 com/p/gtm-oauth/wiki/GTMOAuthIntroduction" rel="nofollow">GTMOAuth 来自 Google 的软件包。它将允许 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];

那里!轻松安全通信,无需用户名和密码!

A late answer I know, but hopefully this will help someone:

MYSITE can be something like thunderofthor.com

Step 1:

Set up 2-legged OAuth for the App Engine domain of interest. To do this, log in as admin to https://www.google.com/a/MYSITE. Under advanced tools, click Manage OAuth domain key. Here, click 'Enable this consumer key' and 'Allow access to all APIs' to enable those options. On Google's side, you can now handle requests that use the MYSITE consumer key and the OAUTHCONSUMERSECRET.

Step 2:

In your servlet code, you can confirm the client has the correct credentials by requesting the OAuthConsumerKey which will be 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());
}

Step 3:

Download the GTMOAuth package from Google. It will allow iOS to talk to your server effortlessly. You won't need the whole package for 2-legged auth. In fact, all you need is the GTMOAuthAuthentication files. To use in your code, do something like the following:

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! Effortless secure communication without requiring usernames and passwords!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文