我正在尝试使用Google API执行简单的OAUTH应用程序。
在程序的中间,我试图在授权后从打开的窗口获取访问代码,因为打开的窗口经过多个重定向。我想知道如何在关闭之前从最终页面获取代码,以便继续使用它。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>quick demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
</head>
<body ng-app="app" ng-controller="ctrl">
<img src="folder/mGHPI.png" ng-click="login()">
</body>
<script>
var app= angular.module("app",[]);
var url;
var openedwindow;
var code;
app.controller("ctrl",function($scope,$http,$window){
$http.get("url").then(function(response){
url=response.data
});
$scope.login=function(){
openedwindow=$window.open(url,"sign in with google","width=500px,height:700px")
code =openedwindow.document.URL;
console.log(code)
};
//window.opener.postMessage("my url is :"+location.href,"*");
window.onmessage = function(e){
console.log(e)
}
})
</script>
</html>