android - ionic 自定义 oauth2 重定向 URL Angular

标签 android angularjs cordova ionic-framework oauth-2.0

我正在使用 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/

相关文章:

android - 构建一个 Android 应用程序,该应用程序将在手机和电脑之间创建远程访问并能够共享文件

Android 即时应用程序 - 无法从基本特征 Assets 中找到符号

android - 服务绑定(bind)到 Activity

css - Angular Material md-select - 无法打开选定用户的框

android - 在 DynamoDB Map 中插入 java.lang.Object

javascript - AngularJS - 错误正文请求 POST

angularjs - 如何多次使用 $compile 服务?

Android PhoneGap Intent 过滤器,浏览器回调正在运行的应用程序?

java - 使用软件包名称中的大写字母构建Cordova Android项目时出错

cordova - 无法使用 phonegap、windows 7 和 android SDK 正确安装 ant