【问题标题】:Ionic custom oauth2 redirect URL Angular离子自定义 oauth2 重定向 URL Angular
【发布时间】:2017-01-02 13:39:14
【问题描述】:

我正在使用 Ionic 和 cordova 构建一个 Android 应用程序。 我有一个 wordpress 网站 - 安装了一些访问功能的 oauth2 插件在哪里。我想先获取代码,然后再发送帖子以检索令牌。我在网络浏览器中对其进行了测试,效果很好:

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' 只是举例;)

【问题讨论】:

    标签: android angularjs cordova ionic-framework oauth2


    【解决方案1】:

    在应用内浏览器中使用 $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();
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 2020-10-24
      • 2014-03-28
      • 2012-09-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      相关资源
      最近更新 更多