2017-01-02 22 views
0

我正在構建一個安卓應用程序Ionic和cordova。 我有一個wordpress網站 - oauth2插件在哪裏安裝了一些訪問功能。我希望先獲取代碼,然後再發送帖子來檢索令牌。我在網絡瀏覽器測試,它工作得很好:離子自定義oauth2重定向URL Angular

location.replace('https://xxx/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=http://192.168.0.129:8100/'); 

即時得到客戶端登錄到我的網站和它重定向到我的應用程序,它在URL站在IP 192.168.0.129:8100與代碼之後的代碼 - 它禾。但在Android的Im使用:

 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應用程序,但它也不適用於我。什麼是重定向網址?如何回到應用程序?當然 「XXX」只是例如;)

回答

0

你已經打開之後的URL中的應用程序瀏覽器$cordovaInAppBrowser,你需要聽這裏,http://ngcordova.com/docs/plugins/inAppBrowser/描述的事件,$cordovaInAppBrowser:loadstart。 所以你可以用下面的方法做,

$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(); 
})