微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter iOS - 在 3rd 方网站或我的自定义重定向页面中重定向停滞 说明代码片段:

如何解决Flutter iOS - 在 3rd 方网站或我的自定义重定向页面中重定向停滞 说明代码片段:

说明

使用 oauth2_client package 连接到 3rd party API。所以我创建了一个自定义客户端,设置了一个网络服务器(因为 3rd 方 API 要求重定向 url 为 HTTPS),并配置了我认为正确的文件。这是尝试这个的坚实一周,我在绳索的尽头,不知道下一步要研究什么,或者这是否是一个错误?我对此表示怀疑,但这是一个很大的障碍。

行为:我对 oauth2 使用隐式授权流。单击第 3 方身份验证时,单击“授权”后,它会挂在该第 3 方应用程序网站上。

oauth hangs on 3rd party website

我也关注了一些flutter-ios documentation here for deep linking。使用“xcrun simctl openurl booted”进行测试 https://www.insightsforynab.com/oauth/redirect.html" 工作正常,它重定向到我的应用。

在向 iOS 添加真正的深层链接之前,它通过了 3rd 方身份验证页面,但随后浏览器将在我的 redirect.html 页面上保持打开状态。

我确实在第 3 方网站上正确标记了我的重定向 URL:

redirect uri on 3rd party website

我只想在他们通过身份验证后关闭该死的浏览器?我可以在 3rd 方网站上看到他们正在接收来自我的虚拟用户的身份验证请求并适当地添加它。只是不能完全越过终点线。

我的问题:

  • 我错过了什么?
  • 如何使用 Flutter 调试应用内浏览器?网络调用似乎在实际应用程序之外,因此我无法使用 DevTools 网络查看器查看它们

代码片段:

调用oauth helper的Flutter按钮组件:

TextButton(
              onpressed: () async {
                AccesstokenResponse resp = await oAuth2Helper.fetchToken();
                //print(resp.accesstoken);
              },

第三方 API 的自定义客户端 --

import "package:oauth2_client/oauth2_client.dart";

class YNABClient extends oauth2client {
  YNABClient({required String redirectUri,required String customUriScheme})
      : super(
            authorizeUrl:
                'https://app.youneedabudget.com/oauth/authorize',//3rd party API
            tokenUrl:
                'https://app.youneedabudget.com/oauth/authorize',//3rd party API
            redirectUri: redirectUri,customUriScheme: customUriScheme);
}

使用 https 作为 customUriScheme 和我自己在网络服务器上的重定向文件实例化客户端。然后调用 oauth 助手并发送自定义客户端。在这里使用隐式授权流程 --

YNABClient client = YNABClient(
    redirectUri: 'https://www.insightsforynab.com/oauth/redirect.html',customUriScheme: 'https');

OAuth2Helper oAuth2Helper = OAuth2Helper(
  client,grantType: OAuth2Helper.IMPLICIT_GRANT,clientId: APIKeys.clientKey,);

iOS info.plist(androidManifest.xml 的平行版本)--

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>www.insightsforynab.com/oauth/redirect.html</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>https</string>
            </array>
        </dict>
    </array>
<key>FlutterDeepLinkingEnabled</key>
<true/>

iOS runner.entitlements(启用深层链接

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:insightsforynab.com</string>
    </array>
</dict>
</plist>

我的网络服务器上的 Apple 应用站点关联文件

{
  "applinks": {
    "apps": [],"details": [
      {
        "appID": "[team-id].com.insights-for-ynab","paths": [ "/oauth/redirect.html"]
      }
    ]
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。