Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Fixed offline function #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions dist/angular-google-gapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
executeCallbacks(api);
}
});
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
}
Expand Down Expand Up @@ -168,14 +170,16 @@
isLoad = true;
deferred.resolve();
});
}, function (e) {
deferred.reject(e);
});
} else {
deferred.resolve();
}
return deferred.promise;
}

function signin(mode, authorizeCallback) {
function signin(mode, authorizeCallback, errorCallback) {
function executeSignin(mode, authorizeCallback){
var config = {client_id: CLIENT_ID, scope: SCOPE, immediate: false, authuser: -1, response_type: RESPONSE_TYPE};
if(mode) {
Expand All @@ -193,16 +197,21 @@
} else {
load().then(function (){
executeSignin(mode, authorizeCallback);
}, function (e) {
if (errorCallback) {
errorCallback(e);
}
});
}
}

function offline() {
var deferred = $q.defer();
var origin = $location.protocol() + "//" + $location.hostname();
if($location.port() != "" || ($location.port() != 443 && $location.protocol()== "https")) {
var origin = $location.protocol() + "://" + $location.host();
if($location.port()) {
origin = origin + ':' + $location.port();
}

var win = $window.open('https://accounts.google.com/o/oauth2/auth?scope='+encodeURI(SCOPE)+'&redirect_uri=postmessage&response_type=code&client_id='+CLIENT_ID+'&access_type=offline&approval_prompt=force&origin='+origin, null, 'width=800, height=600');

$window.addEventListener("message", getCode);
Expand Down Expand Up @@ -276,6 +285,8 @@
}, function () {
deferred.reject();
});
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
Expand All @@ -288,6 +299,8 @@
}, function () {
deferred.reject();
});
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
Expand All @@ -301,6 +314,8 @@
}, function () {
deferred.reject();
});
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
Expand All @@ -309,6 +324,8 @@
var deferred = $q.defer();
load().then(function (){
deferred.resolve($window.gapi.auth.getToken());
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
Expand All @@ -320,6 +337,8 @@
GData.isLogin(false);
GData.getUser(null);
deferred.resolve();
}, function (e) {
deferred.reject(e);
});
return deferred.promise;
},
Expand Down Expand Up @@ -362,6 +381,11 @@
deferred.reject(e);
});
};
$window.onerror = function (e) {
$timeout(function () {
deferred.reject(e);
});
};
script.src = src;
$document[0].body.appendChild(script);
return deferred.promise;
Expand All @@ -386,6 +410,8 @@
for(var i= 0; i < OBSERVER_CALLBACKS.length; i++){
OBSERVER_CALLBACKS[i].resolve();
}
}, function(e) {
deferred.reject(e);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-google-gapi.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/factories/GAuth.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@

function offline() {
var deferred = $q.defer();
var origin = $location.protocol() + "//" + $location.hostname();
if($location.port() != "" || ($location.port() != 443 && $location.protocol()== "https")) {
var origin = $location.protocol() + "://" + $location.host();
if($location.port() && $location.port() !== 443) {
origin = origin + ':' + $location.port();
}

var win = $window.open('https://accounts.google.com/o/oauth2/auth?scope='+encodeURI(SCOPE)+'&redirect_uri=postmessage&response_type=code&client_id='+CLIENT_ID+'&access_type=offline&approval_prompt=force&origin='+origin, null, 'width=800, height=600');

$window.addEventListener("message", getCode);
Expand Down