我正在使用 Ionic 和 cordova 构建一个 Android 应用程序。 我有一个 wordpress 网站——其中安装了具有某些访问功能的 oauth2 插件。我想先获取代码,然后发送帖子以检索 token 。我在网络浏览器中对其进行了测试,它运行良好:
location.replace('https://xxx/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=http://192.168.0.129:8100/');
我在客户端登录到我的网站并将其重定向到我的应用程序后获取代码,该应用程序位于 ip 192.168.0.129:8100 上,url 中有代码 - 它是。但是在我使用的 android 中:
var options = {
clearcache: 'yes',
toolbar: 'no'
};
$cordovaInAppBrowser.open('https://xxx/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=http://192.168.0.129:8100/', '_blank' , options)
.then(function(event) {
}).then(function(){
});
一切正常,但重定向无效 - 它无法再次加载我的应用程序。我做了一些研究,大多数人都把 http://localhost/或 http://localhost/callback回到 android 应用程序,但它也不适合我。什么是重定向 URL?如何返回应用程序? 当然 'xxx' 只是举例;)
最佳答案
在使用 $cordovaInAppBrowser
在应用内浏览器中打开 url 后,您需要监听一个事件,$cordovaInAppBrowser:loadstart
,如此处所述,http://ngcordova.com/docs/plugins/inAppBrowser/。
所以你可以通过下面的方式来做,
$cordovaInAppBrowser.open('https://xxx/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=http://192.168.0.129:8100/', '_blank' , options);
$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event) {
// check event for which url loaded. if it loaded the http://192.168.0.129:8100/ with the access token, then handle it there and close the in app browser with, $cordovaInAppBrowser.close();
})
关于android - ionic 自定义 oauth2 重定向 URL Angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41427925/