问题描述
说明
使用 oauth2_client package 连接到 3rd party API。所以我创建了一个自定义客户端,设置了一个网络服务器(因为 3rd 方 API 要求重定向 url 为 HTTPS),并配置了我认为正确的文件。这是尝试这个的坚实一周,我在绳索的尽头,不知道下一步要研究什么,或者这是否是一个错误?我对此表示怀疑,但这是一个很大的障碍。
行为:我对 oauth2 使用隐式授权流。单击第 3 方身份验证时,单击“授权”后,它会挂在该第 3 方应用程序网站上。
我也关注了一些flutter-ios documentation here for deep linking。使用“xcrun simctl openurl booted”进行测试 https://www.insightsforynab.com/oauth/redirect.html" 工作正常,它重定向到我的应用。
在向 iOS 添加真正的深层链接之前,它通过了 3rd 方身份验证页面,但随后浏览器将在我的 redirect.html 页面上保持打开状态。
我只想在他们通过身份验证后关闭该死的浏览器?我可以在 3rd 方网站上看到他们正在接收来自我的虚拟用户的身份验证请求并适当地添加它。只是不能完全越过终点线。
我的问题:
代码片段:
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>
{
"applinks": {
"apps": [],"details": [
{
"appID": "[team-id].com.insights-for-ynab","paths": [ "/oauth/redirect.html"]
}
]
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)