Advertisement
Guest User

login

a guest
Apr 22nd, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $scope.login = function() {
  2.  
  3.  
  4.             var deferred = $q.defer();
  5.             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');
  6.  
  7.             ref.addEventListener('loadstart', function(event) {
  8.  
  9.                 if ((event.url).startsWith("http://localhost/callback")) {
  10.                     requestToken = (event.url).split("code=")[1];
  11.                     $http({
  12.                         method: "post",
  13.                         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,
  14.                         contentType:"application/x-www-form-urlencoded; charset=utf-8",
  15.                         transformRequest: function(obj) {
  16.                             var str = [];
  17.                             for(var p in obj)
  18.                                 str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  19.                             return str.join("&");
  20.                         }
  21.                     })
  22.                     .success(function (data) {
  23.  
  24.                         console.log(JSON.stringify(data));
  25.  
  26.                         $location.path("/inquiries");
  27.                     })
  28.                     .error(function (data, status) {
  29.                         //alert("ERROR: " + data);
  30.                         deferred.reject("Problem authenticating");
  31.                         console.log(JSON.stringify(data));
  32.                         console.log(status);
  33.                     });
  34.                     ref.close();
  35.  
  36.  
  37.                 }
  38.             });
  39.             ref.addEventListener('exit', function(event) {
  40.                 deferred.reject("The sign in flow was canceled");
  41.             });
  42.         };
  43.  
  44.         if (typeof String.prototype.startsWith != 'function') {
  45.             String.prototype.startsWith = function (str){
  46.                 return this.indexOf(str) == 0;
  47.             };
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement