diff --git a/examples/client/vendor/satellizer.js b/examples/client/vendor/satellizer.js index 432d8e5c..5e9a6aa4 100644 --- a/examples/client/vendor/satellizer.js +++ b/examples/client/vendor/satellizer.js @@ -260,7 +260,7 @@ .then(function(response) { shared.saveToken(response, deferred, isLinking); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -290,7 +290,7 @@ .then(function(response) { shared.saveToken(response, deferred); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -309,7 +309,7 @@ deferred.resolve(response); } }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -354,11 +354,11 @@ .then(function(response) { deferred.resolve(response); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); }) - .catch(function(error) { + .then(null, function(error) { deferred.reject(error); }); @@ -432,11 +432,11 @@ .then(function(response) { deferred.resolve(response); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); diff --git a/satellizer.js b/satellizer.js index 432d8e5c..5e9a6aa4 100644 --- a/satellizer.js +++ b/satellizer.js @@ -260,7 +260,7 @@ .then(function(response) { shared.saveToken(response, deferred, isLinking); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -290,7 +290,7 @@ .then(function(response) { shared.saveToken(response, deferred); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -309,7 +309,7 @@ deferred.resolve(response); } }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); @@ -354,11 +354,11 @@ .then(function(response) { deferred.resolve(response); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); }) - .catch(function(error) { + .then(null, function(error) { deferred.reject(error); }); @@ -432,11 +432,11 @@ .then(function(response) { deferred.resolve(response); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); }) - .catch(function(response) { + .then(null, function(response) { deferred.reject(response); }); diff --git a/satellizer.min.js b/satellizer.min.js index d67de5ed..71cd4f73 100644 --- a/satellizer.min.js +++ b/satellizer.min.js @@ -1 +1 @@ -!function(e,t){"use strict";t.module("satellizer",[]).constant("satellizer.config",{loginOnSignup:!0,loginRedirect:"/",logoutRedirect:"/",signupRedirect:"/login",loginUrl:"/auth/login",signupUrl:"/auth/signup",loginRoute:"/login",signupRoute:"/signup",tokenName:"token",tokenPrefix:"satellizer",unlinkUrl:"/auth/unlink/",providers:{google:{url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",requiredUrlParams:["scope"],optionalUrlParams:["display"],display:"popup",type:"2.0",popupOptions:{width:452,height:633}},facebook:{url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/dialog/oauth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["email"],scopeDelimiter:",",requiredUrlParams:["display","scope"],display:"popup",type:"2.0",popupOptions:{width:481,height:269}},linkedin:{url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",type:"2.0",popupOptions:{width:527,height:582}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:[],scopeDelimiter:" ",type:"2.0",popupOptions:{width:1020,height:618}},twitter:{url:"/auth/twitter",type:"1.0",popupOptions:{width:495,height:645}},yahoo:{url:"/auth/yahoo",type:"1.0",popupOptions:{width:559,height:519}}}}).provider("$auth",["satellizer.config",function(e){Object.defineProperties(this,{logoutRedirect:{get:function(){return e.logoutRedirect},set:function(t){e.logoutRedirect=t}},loginRedirect:{set:function(t){e.loginRedirect=t},get:function(){return e.loginRedirect}},signupRedirect:{get:function(){return e.signupRedirect},set:function(t){e.signupRedirect=t}},loginOnSignup:{get:function(){return e.loginOnSignup},set:function(t){e.loginOnSignup=t}},loginUrl:{get:function(){return e.loginUrl},set:function(t){e.loginUrl=t}},signupUrl:{get:function(){return e.signupUrl},set:function(t){e.signupUrl=t}},loginRoute:{get:function(){return e.loginRoute},set:function(t){e.loginRoute=t}},signupRoute:{get:function(){return e.signupRoute},set:function(t){e.signupRoute=t}},tokenName:{get:function(){return e.tokenName},set:function(t){e.tokenName=t}},tokenPrefix:{get:function(){return e.tokenPrefix},set:function(t){e.tokenPrefix=t}},unlinkUrl:{get:function(){return e.unlinkUrl},set:function(t){e.unlinkUrl=t}}}),t.forEach(Object.keys(e.providers),function(n){this[n]=function(o){return t.extend(e.providers[n],o)}},this);var n=function(n){e.providers[n.name]=e.providers[n.name]||{},t.extend(e.providers[n.name],n)};this.oauth1=function(t){n(t),e.providers[t.name].type="1.0"},this.oauth2=function(t){n(t),e.providers[t.name].type="2.0"},this.$get=["$q","satellizer.shared","satellizer.local","satellizer.oauth",function(e,t,n,o){var i={};return i.authenticate=function(e,t){return o.authenticate(e,!1,t)},i.login=function(e){return n.login(e)},i.signup=function(e){return n.signup(e)},i.logout=function(){return t.logout()},i.isAuthenticated=function(){return t.isAuthenticated()},i.link=function(e,t){return o.authenticate(e,!0,t)},i.unlink=function(e){return o.unlink(e)},i}]}]).factory("satellizer.shared",["$q","$window","$location","satellizer.config",function(e,t,n,o){var i={};return i.saveToken=function(e,i,r){var u=e.data[o.tokenName],a=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;t.localStorage[a]=u,o.loginRedirect&&!r&&n.path(o.loginRedirect),i.resolve(e)},i.isAuthenticated=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n&&!t.atob)return!0;if(n){var i=n.split(".")[1],r=i.replace("-","+").replace("_","/"),u=JSON.parse(t.atob(r)).exp;return Math.round((new Date).getTime()/1e3)<=u}return!1},i.logout=function(){var i=e.defer(),r=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return delete t.localStorage[r],o.logoutRedirect&&n.path(o.logoutRedirect),i.resolve(),i.promise},i}]).factory("satellizer.oauth",["$q","$http","satellizer.config","satellizer.shared","satellizer.Oauth1","satellizer.Oauth2",function(e,t,n,o,i,r){var u={};return u.authenticate=function(t,u,a){var l=e.defer(),c="1.0"===n.providers[t].type?new i:new r;return c.open(n.providers[t],a||{}).then(function(e){o.saveToken(e,l,u)}).catch(function(e){l.reject(e)}),l.promise},u.unlink=function(e){return t.get(n.unlinkUrl+e)},u}]).factory("satellizer.local",["$q","$http","$location","satellizer.utils","satellizer.shared","satellizer.config",function(e,t,n,o,i,r){var u={};return u.login=function(n){var o=e.defer();return t.post(r.loginUrl,n).then(function(e){i.saveToken(e,o)}).catch(function(e){o.reject(e)}),o.promise},u.signup=function(o){var u=e.defer();return t.post(r.signupUrl,o).then(function(e){r.loginOnSignup?i.saveToken(e,u):(n.path(r.signupRedirect),u.resolve(e))}).catch(function(e){u.reject(e)}),u.promise},u}]).factory("satellizer.Oauth2",["$q","$http","satellizer.popup","satellizer.utils",function(e,n,o,i){return function(){var r={url:null,name:null,scope:null,scopeDelimiter:null,clientId:null,redirectUri:null,popupOptions:null,authorizationEndpoint:null,requiredUrlParams:null,optionalUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code"},u={};return u.open=function(n,i){t.extend(r,n);var a=e.defer(),l=u.buildUrl();return o.open(l,r.popupOptions).then(function(e){u.exchangeForToken(e,i).then(function(e){a.resolve(e)}).catch(function(e){a.reject(e)})}).catch(function(e){a.reject(e)}),a.promise},u.exchangeForToken=function(e,o){var i=t.extend({},o,{code:e.code,clientId:r.clientId,redirectUri:r.redirectUri});return n.post(r.url,i)},u.buildUrl=function(){var e=r.authorizationEndpoint,t=u.buildQueryString();return[e,t].join("?")},u.buildQueryString=function(){var e=[],n=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(n,function(n){t.forEach(r[n],function(t){var n=i.camelCase(t),o=r[n];"scope"===t&&Array.isArray(o)&&(o=o.join(r.scopeDelimiter),r.scopePrefix&&(o=[r.scopePrefix,o].join(r.scopeDelimiter))),e.push([t,encodeURIComponent(o)])})}),e.map(function(e){return e.join("=")}).join("&")},u}}]).factory("satellizer.Oauth1",["$q","$http","satellizer.popup",function(e,n,o){return function(){var i={url:null,name:null,popupOptions:null},r={};return r.open=function(n,u){t.extend(i,n);var a=e.defer();return o.open(i.url,i.popupOptions).then(function(e){r.exchangeForToken(e,u).then(function(e){a.resolve(e)}).catch(function(e){a.reject(e)})}).catch(function(e){a.reject(e)}),a.promise},r.exchangeForToken=function(e,o){var u=t.extend({},o,e),a=r.buildQueryString(u);return n.get(i.url+"?"+a)},r.buildQueryString=function(e){var n=[];return t.forEach(e,function(e,t){n.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),n.join("&")},r}}]).factory("satellizer.popup",["$q","$interval","$window","$location","satellizer.utils",function(n,o,i,r,u){var a=null,l=null,c={};return c.popupWindow=a,c.open=function(t,o){var i=n.defer(),r=c.stringifyOptions(c.prepareOptions(o||{}));return a=e.open(t,"_blank",r),a&&a.focus&&a.focus(),c.pollPopup(i),i.promise},c.pollPopup=function(e){l=o(function(){try{if(a.document.domain===document.domain&&a.location.search){var t=a.location.search.substring(1),n=Object.keys(r.search()).length?r.search():u.parseQueryString(t);n.oauth_token&&n.oauth_verifier?e.resolve({oauth_token:n.oauth_token,oauth_verifier:n.oauth_verifier}):n.code?e.resolve({code:n.code}):n.error&&e.reject({error:n.error}),a.close(),o.cancel(l)}}catch(i){}a.closed&&(o.cancel(l),e.reject({data:"Authorization Failed"}))},35)},c.prepareOptions=function(e){var n=e.width||500,o=e.height||500;return t.extend({width:n,height:o,left:i.screenX+(i.outerWidth-n)/2,top:i.screenY+(i.outerHeight-o)/2.5},e)},c.stringifyOptions=function(e){var n=[];return t.forEach(e,function(e,t){n.push(t+"="+e)}),n.join(",")},c}]).service("satellizer.utils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,n,o){return o?n.toUpperCase():n})},this.parseQueryString=function(e){var n,o,i={};return t.forEach((e||"").split("&"),function(e){e&&(o=e.split("="),n=decodeURIComponent(o[0]),i[n]=t.isDefined(o[1])?decodeURIComponent(o[1]):!0)}),i}}).config(["$httpProvider","satellizer.config",function(e,t){e.interceptors.push(["$q",function(e){var n=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName;return{request:function(e){return localStorage.getItem(n)&&(e.headers.Authorization="Bearer "+localStorage.getItem(n)),e},responseError:function(t){return 401===t.status&&localStorage.removeItem(n),e.reject(t)}}}])}])}(window,window.angular); \ No newline at end of file +!function(e,t){"use strict";t.module("satellizer",[]).constant("satellizer.config",{loginOnSignup:!0,loginRedirect:"/",logoutRedirect:"/",signupRedirect:"/login",loginUrl:"/auth/login",signupUrl:"/auth/signup",loginRoute:"/login",signupRoute:"/signup",tokenName:"token",tokenPrefix:"satellizer",unlinkUrl:"/auth/unlink/",providers:{google:{url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",requiredUrlParams:["scope"],optionalUrlParams:["display"],display:"popup",type:"2.0",popupOptions:{width:452,height:633}},facebook:{url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/dialog/oauth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["email"],scopeDelimiter:",",requiredUrlParams:["display","scope"],display:"popup",type:"2.0",popupOptions:{width:481,height:269}},linkedin:{url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",type:"2.0",popupOptions:{width:527,height:582}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:[],scopeDelimiter:" ",type:"2.0",popupOptions:{width:1020,height:618}},twitter:{url:"/auth/twitter",type:"1.0",popupOptions:{width:495,height:645}},yahoo:{url:"/auth/yahoo",type:"1.0",popupOptions:{width:559,height:519}}}}).provider("$auth",["satellizer.config",function(e){Object.defineProperties(this,{logoutRedirect:{get:function(){return e.logoutRedirect},set:function(t){e.logoutRedirect=t}},loginRedirect:{set:function(t){e.loginRedirect=t},get:function(){return e.loginRedirect}},signupRedirect:{get:function(){return e.signupRedirect},set:function(t){e.signupRedirect=t}},loginOnSignup:{get:function(){return e.loginOnSignup},set:function(t){e.loginOnSignup=t}},loginUrl:{get:function(){return e.loginUrl},set:function(t){e.loginUrl=t}},signupUrl:{get:function(){return e.signupUrl},set:function(t){e.signupUrl=t}},loginRoute:{get:function(){return e.loginRoute},set:function(t){e.loginRoute=t}},signupRoute:{get:function(){return e.signupRoute},set:function(t){e.signupRoute=t}},tokenName:{get:function(){return e.tokenName},set:function(t){e.tokenName=t}},tokenPrefix:{get:function(){return e.tokenPrefix},set:function(t){e.tokenPrefix=t}},unlinkUrl:{get:function(){return e.unlinkUrl},set:function(t){e.unlinkUrl=t}}}),t.forEach(Object.keys(e.providers),function(n){this[n]=function(o){return t.extend(e.providers[n],o)}},this);var n=function(n){e.providers[n.name]=e.providers[n.name]||{},t.extend(e.providers[n.name],n)};this.oauth1=function(t){n(t),e.providers[t.name].type="1.0"},this.oauth2=function(t){n(t),e.providers[t.name].type="2.0"},this.$get=["$q","satellizer.shared","satellizer.local","satellizer.oauth",function(e,t,n,o){var i={};return i.authenticate=function(e,t){return o.authenticate(e,!1,t)},i.login=function(e){return n.login(e)},i.signup=function(e){return n.signup(e)},i.logout=function(){return t.logout()},i.isAuthenticated=function(){return t.isAuthenticated()},i.link=function(e,t){return o.authenticate(e,!0,t)},i.unlink=function(e){return o.unlink(e)},i}]}]).factory("satellizer.shared",["$q","$window","$location","satellizer.config",function(e,t,n,o){var i={};return i.saveToken=function(e,i,r){var u=e.data[o.tokenName],l=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;t.localStorage[l]=u,o.loginRedirect&&!r&&n.path(o.loginRedirect),i.resolve(e)},i.isAuthenticated=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n&&!t.atob)return!0;if(n){var i=n.split(".")[1],r=i.replace("-","+").replace("_","/"),u=JSON.parse(t.atob(r)).exp;return Math.round((new Date).getTime()/1e3)<=u}return!1},i.logout=function(){var i=e.defer(),r=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return delete t.localStorage[r],o.logoutRedirect&&n.path(o.logoutRedirect),i.resolve(),i.promise},i}]).factory("satellizer.oauth",["$q","$http","satellizer.config","satellizer.shared","satellizer.Oauth1","satellizer.Oauth2",function(e,t,n,o,i,r){var u={};return u.authenticate=function(t,u,l){var a=e.defer(),c="1.0"===n.providers[t].type?new i:new r;return c.open(n.providers[t],l||{}).then(function(e){o.saveToken(e,a,u)}).then(null,function(e){a.reject(e)}),a.promise},u.unlink=function(e){return t.get(n.unlinkUrl+e)},u}]).factory("satellizer.local",["$q","$http","$location","satellizer.utils","satellizer.shared","satellizer.config",function(e,t,n,o,i,r){var u={};return u.login=function(n){var o=e.defer();return t.post(r.loginUrl,n).then(function(e){i.saveToken(e,o)}).then(null,function(e){o.reject(e)}),o.promise},u.signup=function(o){var u=e.defer();return t.post(r.signupUrl,o).then(function(e){r.loginOnSignup?i.saveToken(e,u):(n.path(r.signupRedirect),u.resolve(e))}).then(null,function(e){u.reject(e)}),u.promise},u}]).factory("satellizer.Oauth2",["$q","$http","satellizer.popup","satellizer.utils",function(e,n,o,i){return function(){var r={url:null,name:null,scope:null,scopeDelimiter:null,clientId:null,redirectUri:null,popupOptions:null,authorizationEndpoint:null,requiredUrlParams:null,optionalUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code"},u={};return u.open=function(n,i){t.extend(r,n);var l=e.defer(),a=u.buildUrl();return o.open(a,r.popupOptions).then(function(e){u.exchangeForToken(e,i).then(function(e){l.resolve(e)}).then(null,function(e){l.reject(e)})}).then(null,function(e){l.reject(e)}),l.promise},u.exchangeForToken=function(e,o){var i=t.extend({},o,{code:e.code,clientId:r.clientId,redirectUri:r.redirectUri});return n.post(r.url,i)},u.buildUrl=function(){var e=r.authorizationEndpoint,t=u.buildQueryString();return[e,t].join("?")},u.buildQueryString=function(){var e=[],n=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(n,function(n){t.forEach(r[n],function(t){var n=i.camelCase(t),o=r[n];"scope"===t&&Array.isArray(o)&&(o=o.join(r.scopeDelimiter),r.scopePrefix&&(o=[r.scopePrefix,o].join(r.scopeDelimiter))),e.push([t,encodeURIComponent(o)])})}),e.map(function(e){return e.join("=")}).join("&")},u}}]).factory("satellizer.Oauth1",["$q","$http","satellizer.popup",function(e,n,o){return function(){var i={url:null,name:null,popupOptions:null},r={};return r.open=function(n,u){t.extend(i,n);var l=e.defer();return o.open(i.url,i.popupOptions).then(function(e){r.exchangeForToken(e,u).then(function(e){l.resolve(e)}).then(null,function(e){l.reject(e)})}).then(null,function(e){l.reject(e)}),l.promise},r.exchangeForToken=function(e,o){var u=t.extend({},o,e),l=r.buildQueryString(u);return n.get(i.url+"?"+l)},r.buildQueryString=function(e){var n=[];return t.forEach(e,function(e,t){n.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),n.join("&")},r}}]).factory("satellizer.popup",["$q","$interval","$window","$location","satellizer.utils",function(n,o,i,r,u){var l=null,a=null,c={};return c.popupWindow=l,c.open=function(t,o){var i=n.defer(),r=c.stringifyOptions(c.prepareOptions(o||{}));return l=e.open(t,"_blank",r),l&&l.focus&&l.focus(),c.pollPopup(i),i.promise},c.pollPopup=function(e){a=o(function(){try{if(l.document.domain===document.domain&&l.location.search){var t=l.location.search.substring(1),n=Object.keys(r.search()).length?r.search():u.parseQueryString(t);n.oauth_token&&n.oauth_verifier?e.resolve({oauth_token:n.oauth_token,oauth_verifier:n.oauth_verifier}):n.code?e.resolve({code:n.code}):n.error&&e.reject({error:n.error}),l.close(),o.cancel(a)}}catch(i){}l.closed&&(o.cancel(a),e.reject({data:"Authorization Failed"}))},35)},c.prepareOptions=function(e){var n=e.width||500,o=e.height||500;return t.extend({width:n,height:o,left:i.screenX+(i.outerWidth-n)/2,top:i.screenY+(i.outerHeight-o)/2.5},e)},c.stringifyOptions=function(e){var n=[];return t.forEach(e,function(e,t){n.push(t+"="+e)}),n.join(",")},c}]).service("satellizer.utils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,n,o){return o?n.toUpperCase():n})},this.parseQueryString=function(e){var n,o,i={};return t.forEach((e||"").split("&"),function(e){e&&(o=e.split("="),n=decodeURIComponent(o[0]),i[n]=t.isDefined(o[1])?decodeURIComponent(o[1]):!0)}),i}}).config(["$httpProvider","satellizer.config",function(e,t){e.interceptors.push(["$q",function(e){var n=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName;return{request:function(e){return localStorage.getItem(n)&&(e.headers.Authorization="Bearer "+localStorage.getItem(n)),e},responseError:function(t){return 401===t.status&&localStorage.removeItem(n),e.reject(t)}}}])}])}(window,window.angular); \ No newline at end of file