Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.login = function() {
- var deferred = $q.defer();
- var ref = window.cordova.InAppBrowser.open('https://wespot-arlearn.appspot.com/Login.html?client_id=wespotClientId&redirect_uri=http://localhost/callback&response_type=code&scope=profile+email', '_blank', 'location=no,clearsessioncache=yes,clearcache=yes,toolbar=yes');
- ref.addEventListener('loadstart', function(event) {
- if ((event.url).startsWith("http://localhost/callback")) {
- requestToken = (event.url).split("code=")[1];
- $http({
- method: "post",
- url: "https://wespot-arlearn.appspot.com/oauth/token?grant_type=authorization_code&client_id="+clientId+"&client_secret="+clientSecret+"&redirect_uri=http://localhost/callback&code="+requestToken,
- contentType:"application/x-www-form-urlencoded; charset=utf-8",
- transformRequest: function(obj) {
- var str = [];
- for(var p in obj)
- str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
- return str.join("&");
- }
- })
- .success(function (data) {
- console.log(JSON.stringify(data));
- $location.path("/inquiries");
- })
- .error(function (data, status) {
- //alert("ERROR: " + data);
- deferred.reject("Problem authenticating");
- console.log(JSON.stringify(data));
- console.log(status);
- });
- ref.close();
- }
- });
- ref.addEventListener('exit', function(event) {
- deferred.reject("The sign in flow was canceled");
- });
- };
- if (typeof String.prototype.startsWith != 'function') {
- String.prototype.startsWith = function (str){
- return this.indexOf(str) == 0;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement