菜鸟教程小白 发表于 2022-12-12 16:28:30

ios - Google 登录 iOS 和网络


                                            <p><p>我正在构建一个包含 Web 和 iOS 应用程序的系统。 Web 部件需要可在移动部件上使用的身份验证,反之亦然。
我想在网络和移动部分添加对谷歌登录的支持。对于测试,我使用了来自 </p> 的代码

<p> <a href="https://developers.google.com/identity/sign-in/ios/start-integrating" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/ios/start-integrating</a> </p>

<p>适用于 iOS 和 </p>

<p> <a href="https://developers.google.com/identity/sign-in/web/" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/web/</a> </p>

<p>用于 Web 部件。
应用程序和网络(电子邮件、个人资料)的范围相同</p>

<p><strong>预期流量</strong></p>

<ol>
<li>用户使用 google 登录并从移动设备(或网络)授予访问权限</li>
<li>用户访问网站(或应用程序)</li>
<li>用户使用 google 登录</li>
<li>无需再次授予权限</li>
</ol>

<p><strong>我得到了什么</strong></p>

<ol start="5">
<li>用户使用 google 登录并从移动设备授予访问权限</li>
<li>用户访问网站</li>
<li>用户使用 google 登录</li>
<li>再次请求相同的权限</li>
</ol>

<p>如何避免再次请求许可?来自文档 (<a href="https://developers.google.com/identity/sign-in/web/cross-platform-sign-in" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/web/cross-platform-sign-in</a>)
似乎可以获得预期的流量,但实际上我无法获得它。 iOS 和 Web 在同一个谷歌开发者项目中。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我按照以下指南按预期完成了这项工作:<a href="https://developers.google.com/identity/protocols/CrossClientAuth" rel="noreferrer noopener nofollow">https://developers.google.com/identity/protocols/CrossClientAuth</a>
<a href="https://developers.google.com/identity/sign-in/ios/offline-access" rel="noreferrer noopener nofollow">https://developers.google.com/identity/sign-in/ios/offline-access</a> </p>

<p>你需要做的是:</p>

<p>首先添加
<code>.serverClientID = @"SERVER_CLIENT_ID";</code></p>

<p>在您的 iOS appDelegate 中。当用户通过应用程序进行身份验证时,您现在可以通过 <code>GIDGoogleUser</code> 对象的 <code>serverAuthCode</code> 属性检索对您的 server_client_id 有效的 token 。 </p>

<p>将 token 发送到服务器并在 token 端点(/oauth2/v3/token)上验证它 <code>redirect_uri</code> 必须为空,而 <code>grant_type</code> 必须是 <code>authorization_code </code>否则你会得到 400 响应。</p>

<p>您的服务器现已通过身份验证,用户何时登录网站时将不再询问权限。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Google 登录 iOS 和网络,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32903351/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32903351/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Google 登录 iOS 和网络