菜鸟教程小白 发表于 2022-12-13 07:56:13

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


                                            <p><p>我正在尝试使用 OAuth 将 iOS 应用程序与 Google App Engine 集成。我发现 GTM 有一个 OAuthController-- <a href="http://code.google.com/p/gtm-oauth/" rel="noreferrer noopener nofollow">http://code.google.com/p/gtm-oauth/</a> </p>

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

<pre><code>    - (id)initWithScope:(NSString *)scope
      language:(NSString *)language
appServiceName:(NSString *)keychainAppServiceName
      delegate:(id)delegate
finishedSelector:(SEL)finishedSelector;
</code></pre>

<p>我尝试使用我的 App Engine 应用程序的地址 (<a href="http://my-app-name.appspot.com" rel="noreferrer noopener nofollow">http://my-app-name.appspot.com</a>),但没有成功。</p>

<p>提前致谢!</p>

<p>顺便说一句,这是对 <a href="https://stackoverflow.com/questions/4600844/authenticating-into-google-app-engine-from-an-ios-device" rel="noreferrer noopener nofollow">Authenticating into Google App Engine from an iOS device</a> 的后续问题。 .</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我知道一个较晚的答案,但希望这会对某人有所帮助:</p>

<p><strong>MYSITE</strong> 可以是 Thunderofthor.com 之类的网站</p>

<p>第 1 步:</p>

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

<p>第 2 步:</p>

<p>在您的 servlet 代码中,您可以通过请求 <strong>MYSITE</strong></p> 的 OAuthConsumerKey 来确认客户端具有正确的凭据

<pre><code>public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String user = null;
try {
   OAuthService oauth = OAuthServiceFactory.getOAuthService();
   user = oauth.getOAuthConsumerKey();
   LOG.info(&#34;Authenticated: &#34; + user);
} catch (OAuthRequestException e) {
    LOG.info(&#34;Not authenticated: &#34; + e.getMessage());
}
</code></pre>

<p>第 3 步:</p>

<p>下载<a href="http://code.google.com/p/gtm-oauth/wiki/GTMOAuthIntroduction" rel="noreferrer noopener nofollow">GTMOAuth</a>来自谷歌的包。它将允许 iOS 毫不费力地与您的服务器通信。 2-legged auth 不需要整个软件包。事实上,您所需要的只是 GTMOAuthAuthentication 文件。要在您的代码中使用,请执行以下操作:</p>

<pre><code>NSURL *url = ;
NSMutableURLRequest *request = ;

GTMOAuthAuthentication *auth = [ initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1 consumerKey:@&#34;MYSITE&#34; privateKey:@&#34;OAUTHCONSUMERSECRET&#34;] ;
;

;

// Perform request and get JSON back as a NSData object
NSHTTPURLResponse *response = nil;
NSError *error = nil;

NSData *data = ;
</code></pre>

<p>那里!无需用户名和密码即可轻松进行安全通信!</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/6183313/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/6183313/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 使用 Google Toolbox for Mac OAuth for Google App Engine