I wrote a module with 3 services that execute the oauth (and set the api key) for the google api and return the token object if the promise is positive.
Here is the whole working module:
angular.module('gapiOAuth', [])
.controller('gapiOAuthController', ['$scope', function($scope){
}])
.factory('gapiCredentialsSrvc', function(){
return {
gapiClientId: 'xxx',
gapiScopeUrl: ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/blogger'],
gapiKey: 'xxx'
}
})
.factory('gapiGetTokenSrvc', ['$q','gapiCredentialsSrvc', function($q, gapiCredentialsSrvc){
return function (){
var q = $q.defer();
angular.element(document).ready(function(){
gapi.auth.authorize({client_id: gapiCredentialsSrvc.gapiClientId, scope: gapiCredentialsSrvc.gapiScopeUrl, immediate: true}, function(response){
if(response && !response.error){
q.resolve(response);
} else {
q.reject({});
}
});
});
return q.promise;
};
}])
.factory('gapiLogInSrvc',['$q','gapiCredentialsSrvc', function($q, gapiCredentialsSrvc){
return function(){
var q = $q.defer();
angular.element(document).ready(function(){
gapi.auth.authorize({client_id: gapiCredentialsSrvc.gapiClientId, scope: gapiCredentialsSrvc.gapiScopeUrl, immediate: false}, function(response){
if(response && !response.error){
q.resolve(response);
}else{
q.reject(response.error);
}
});
});
return q.promise;
};
}])
.factory('gapiSetApiKeySrvc',['gapiCredentialsSrvc', function(gapiCredentialsSrvc){
return function(){
angular.element(document).ready(function(){
gapi.client.setApiKey(gapiCredentialsSrvc.gapiKey);
return true;
});
};
}])
Do you think there will be security issues if I put this code I made onto the client side?
How can I improve it?