diff --git a/examples/client/vendor/satellizer.js b/examples/client/vendor/satellizer.js index 6f48c1e1..05a03151 100644 --- a/examples/client/vendor/satellizer.js +++ b/examples/client/vendor/satellizer.js @@ -29,10 +29,9 @@ scope: ['profile', 'email'], scopePrefix: 'openid', scopeDelimiter: ' ', - requiredUrlParams: ['scope', 'state'], + requiredUrlParams: ['scope'], optionalUrlParams: ['display'], display: 'popup', - state: 'YOYO', type: '2.0', popupOptions: { width: 452, height: 633 } }, @@ -359,10 +358,11 @@ .factory('satellizer.Oauth2', [ '$q', '$http', + '$window', 'satellizer.popup', 'satellizer.utils', 'satellizer.config', - function($q, $http, popup, utils) { + function($q, $http, $window, popup, utils, config) { return function() { var defaults = { @@ -387,12 +387,16 @@ oauth2.open = function(options, userData) { angular.extend(defaults, options); + if (defaults.state) { + $window.localStorage.state = defaults.state(); + } + var url = defaults.authorizationEndpoint + '?' + oauth2.buildQueryString(); return popup.open(url, defaults.popupOptions) .then(function(oauthData) { - if (oauthData.state && oauthData.state !== defaults.state) { - throw new Error('Invalid state parameter'); + if (oauthData.state && oauthData.state !== $window.localStorage.state) { + return $q.reject({ data: 'Invalid state parameter' }); } if (defaults.responseType === 'token') { return oauthData; @@ -411,7 +415,6 @@ }); angular.forEach(defaults.responseParams, function(param) { - console.log(param); data[param] = oauthData[param]; }); @@ -427,6 +430,10 @@ var camelizedName = utils.camelCase(paramName); var paramValue = defaults[camelizedName]; + if (paramName === 'state') { + paramValue = $window.localStorage.state; + } + if (paramName === 'scope' && Array.isArray(paramValue)) { paramValue = paramValue.join(defaults.scopeDelimiter); diff --git a/satellizer.js b/satellizer.js index 6f48c1e1..05a03151 100644 --- a/satellizer.js +++ b/satellizer.js @@ -29,10 +29,9 @@ scope: ['profile', 'email'], scopePrefix: 'openid', scopeDelimiter: ' ', - requiredUrlParams: ['scope', 'state'], + requiredUrlParams: ['scope'], optionalUrlParams: ['display'], display: 'popup', - state: 'YOYO', type: '2.0', popupOptions: { width: 452, height: 633 } }, @@ -359,10 +358,11 @@ .factory('satellizer.Oauth2', [ '$q', '$http', + '$window', 'satellizer.popup', 'satellizer.utils', 'satellizer.config', - function($q, $http, popup, utils) { + function($q, $http, $window, popup, utils, config) { return function() { var defaults = { @@ -387,12 +387,16 @@ oauth2.open = function(options, userData) { angular.extend(defaults, options); + if (defaults.state) { + $window.localStorage.state = defaults.state(); + } + var url = defaults.authorizationEndpoint + '?' + oauth2.buildQueryString(); return popup.open(url, defaults.popupOptions) .then(function(oauthData) { - if (oauthData.state && oauthData.state !== defaults.state) { - throw new Error('Invalid state parameter'); + if (oauthData.state && oauthData.state !== $window.localStorage.state) { + return $q.reject({ data: 'Invalid state parameter' }); } if (defaults.responseType === 'token') { return oauthData; @@ -411,7 +415,6 @@ }); angular.forEach(defaults.responseParams, function(param) { - console.log(param); data[param] = oauthData[param]; }); @@ -427,6 +430,10 @@ var camelizedName = utils.camelCase(paramName); var paramValue = defaults[camelizedName]; + if (paramName === 'state') { + paramValue = $window.localStorage.state; + } + if (paramName === 'scope' && Array.isArray(paramValue)) { paramValue = paramValue.join(defaults.scopeDelimiter); diff --git a/satellizer.min.js b/satellizer.min.js index eae55056..f6c61ec7 100644 --- a/satellizer.min.js +++ b/satellizer.min.js @@ -3,4 +3,4 @@ * (c) 2014 Sahat Yalkabov * License: MIT */ -!function(e,t){"use strict";t.module("satellizer",[]).constant("satellizer.config",{httpInterceptor:!0,loginOnSignup:!0,loginRedirect:"/",logoutRedirect:"/",signupRedirect:"/login",loginUrl:"/auth/login",signupUrl:"/auth/signup",loginRoute:"/login",signupRoute:"/signup",tokenName:"token",tokenPrefix:"satellizer",unlinkUrl:"/auth/unlink/",authHeader:"Authorization",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","state"],optionalUrlParams:["display"],display:"popup",state:"YOYO",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:580,height:400}},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:{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}},yahoo:{url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:[],scopeDelimiter:",",type:"2.0",popupOptions:{width:559,height:519}},twitter:{url:"/auth/twitter",type:"1.0",popupOptions:{width:495,height:645}},live:{url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["wl.basic"],scopeDelimiter:" ",requiredUrlParams:["display","scope"],display:"popup",type:"2.0",popupOptions:{width:500,height:560}}}}).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}},authHeader:{get:function(){return e.authHeader},set:function(t){e.authHeader=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 r={};return r.authenticate=function(e,t){return o.authenticate(e,!1,t)},r.login=function(e){return n.login(e)},r.signup=function(e){return n.signup(e)},r.logout=function(){return t.logout()},r.isAuthenticated=function(){return t.isAuthenticated()},r.link=function(e,t){return o.authenticate(e,!0,t)},r.unlink=function(e){return o.unlink(e)},r.getToken=function(){return t.getToken()},r.setToken=function(e,n){t.setToken({access_token:e},n)},r.removeToken=function(){return t.removeToken()},r.getPayload=function(){return t.getPayload()},r}]}]).factory("satellizer.shared",["$q","$window","$location","satellizer.config",function(e,t,n,o){var r={};return r.getToken=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return t.localStorage[e]},r.getPayload=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n&&3===n.split(".").length){var r=n.split(".")[1],i=r.replace("-","+").replace("_","/");return JSON.parse(t.atob(i))}},r.setToken=function(e,r){var i=e.access_token||e.data[o.tokenName],a=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;if(!i)throw new Error('Expecting a token named "'+o.tokenName+'" but instead got: '+JSON.stringify(e.data));t.localStorage[a]=i,o.loginRedirect&&!r&&n.path(o.loginRedirect)},r.removeToken=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;delete t.localStorage[e]},r.isAuthenticated=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n){if(3===n.split(".").length){var r=n.split(".")[1],i=r.replace("-","+").replace("_","/"),a=JSON.parse(t.atob(i)).exp;return Math.round((new Date).getTime()/1e3)<=a}return!0}return!1},r.logout=function(){var r=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return delete t.localStorage[r],o.logoutRedirect&&n.path(o.logoutRedirect),e.when()},r}]).factory("satellizer.oauth",["$q","$http","satellizer.config","satellizer.shared","satellizer.Oauth1","satellizer.Oauth2",function(e,t,n,o,r,i){var a={};return a.authenticate=function(e,t,a){var u="1.0"===n.providers[e].type?new r:new i;return u.open(n.providers[e],a||{}).then(function(e){return o.setToken(e,t),e})},a.unlink=function(e){return t.get(n.unlinkUrl+e)},a}]).factory("satellizer.local",["$q","$http","$location","satellizer.utils","satellizer.shared","satellizer.config",function(e,t,n,o,r,i){var a={};return a.login=function(e){return t.post(i.loginUrl,e).then(function(e){return r.setToken(e),e})},a.signup=function(e){return t.post(i.signupUrl,e).then(function(e){return i.loginOnSignup?r.setToken(e):i.signupRedirect&&n.path(i.signupRedirect),e})},a}]).factory("satellizer.Oauth2",["$q","$http","satellizer.popup","satellizer.utils","satellizer.config",function(e,n,o,r){return function(){var e={url:null,name:null,state:null,scope:null,scopeDelimiter:null,clientId:null,redirectUri:null,popupOptions:null,authorizationEndpoint:null,responseParams:null,requiredUrlParams:null,optionalUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code"},i={};return i.open=function(n,r){t.extend(e,n);var a=e.authorizationEndpoint+"?"+i.buildQueryString();return o.open(a,e.popupOptions).then(function(t){if(t.state&&t.state!==e.state)throw new Error("Invalid state parameter");return"token"===e.responseType?t:i.exchangeForToken(t,r)})},i.exchangeForToken=function(o,r){var i=t.extend({},r,{code:o.code,clientId:e.clientId,redirectUri:e.redirectUri});return t.forEach(e.responseParams,function(e){console.log(e),i[e]=o[e]}),n.post(e.url,i,{withCredentials:!0})},i.buildQueryString=function(){var n=[],o=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(o,function(o){t.forEach(e[o],function(t){var o=r.camelCase(t),i=e[o];"scope"===t&&Array.isArray(i)&&(i=i.join(e.scopeDelimiter),e.scopePrefix&&(i=[e.scopePrefix,i].join(e.scopeDelimiter))),n.push([t,i])})}),n.map(function(e){return e.join("=")}).join("&")},i}}]).factory("satellizer.Oauth1",["$q","$http","satellizer.popup",function(e,n,o){return function(){var e={url:null,name:null,popupOptions:null},r={};return r.open=function(n,i){return t.extend(e,n),o.open(e.url,e.popupOptions).then(function(e){return r.exchangeForToken(e,i)})},r.exchangeForToken=function(o,i){var a=t.extend({},i,o),u=r.buildQueryString(a);return n.get(e.url+"?"+u)},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,r,i,a){var u=null,l=null,c={};return c.popupWindow=u,c.open=function(t,n){var o=c.stringifyOptions(c.prepareOptions(n||{}));return u=e.open(t,"_blank",o),u&&u.focus&&u.focus(),c.pollPopup()},c.pollPopup=function(){var e=n.defer();return l=o(function(){try{if(u.document.domain===document.domain&&(u.location.search||u.location.hash)){var n=u.location.search.substring(1).replace(/\/$/,""),r=u.location.hash.substring(1).replace(/\/$/,""),i=a.parseQueryString(r),c=a.parseQueryString(n);t.extend(c,i),c.error?e.reject({error:c.error}):e.resolve(c),u.close(),o.cancel(l)}}catch(s){}u.closed&&(o.cancel(l),e.reject({data:"Authorization Failed"}))},35),e.promise},c.prepareOptions=function(e){var n=e.width||500,o=e.height||500;return t.extend({width:n,height:o,left:r.screenX+(r.outerWidth-n)/2,top:r.screenY+(r.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,r={};return t.forEach((e||"").split("&"),function(e){e&&(o=e.split("="),n=decodeURIComponent(o[0]),r[n]=t.isDefined(o[1])?decodeURIComponent(o[1]):!0)}),r}}).config(["$httpProvider","satellizer.config",function(e,t){t.httpInterceptor&&e.interceptors.push(["$q",function(e){var n=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName;return{request:function(e){var o=localStorage.getItem(n);return o&&(o="Authorization"===t.authHeader?"Bearer "+o:o,e.headers[t.authHeader]=o),e},responseError:function(t){return e.reject(t)}}}])}])}(window,window.angular),function(){function e(e){this.message=e}var t="undefined"!=typeof exports?exports:this,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.prototype=new Error,e.prototype.name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var o,r,i=String(t),a=0,u=n,l="";i.charAt(0|a)||(u="=",a%1);l+=u.charAt(63&o>>8-a%1*8)){if(r=i.charCodeAt(a+=.75),r>255)throw new e("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|r}return l}),t.atob||(t.atob=function(t){var o=String(t).replace(/=+$/,"");if(o.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,i,a=0,u=0,l="";i=o.charAt(u++);~i&&(r=a%4?64*r+i:i,a++%4)?l+=String.fromCharCode(255&r>>(-2*a&6)):0)i=n.indexOf(i);return l})}(); \ No newline at end of file +!function(e,t){"use strict";t.module("satellizer",[]).constant("satellizer.config",{httpInterceptor:!0,loginOnSignup:!0,loginRedirect:"/",logoutRedirect:"/",signupRedirect:"/login",loginUrl:"/auth/login",signupUrl:"/auth/signup",loginRoute:"/login",signupRoute:"/signup",tokenName:"token",tokenPrefix:"satellizer",unlinkUrl:"/auth/unlink/",authHeader:"Authorization",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:580,height:400}},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:{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}},yahoo:{url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:[],scopeDelimiter:",",type:"2.0",popupOptions:{width:559,height:519}},twitter:{url:"/auth/twitter",type:"1.0",popupOptions:{width:495,height:645}},live:{url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin||e.location.protocol+"//"+e.location.host,scope:["wl.basic"],scopeDelimiter:" ",requiredUrlParams:["display","scope"],display:"popup",type:"2.0",popupOptions:{width:500,height:560}}}}).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}},authHeader:{get:function(){return e.authHeader},set:function(t){e.authHeader=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 r={};return r.authenticate=function(e,t){return o.authenticate(e,!1,t)},r.login=function(e){return n.login(e)},r.signup=function(e){return n.signup(e)},r.logout=function(){return t.logout()},r.isAuthenticated=function(){return t.isAuthenticated()},r.link=function(e,t){return o.authenticate(e,!0,t)},r.unlink=function(e){return o.unlink(e)},r.getToken=function(){return t.getToken()},r.setToken=function(e,n){t.setToken({access_token:e},n)},r.removeToken=function(){return t.removeToken()},r.getPayload=function(){return t.getPayload()},r}]}]).factory("satellizer.shared",["$q","$window","$location","satellizer.config",function(e,t,n,o){var r={};return r.getToken=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return t.localStorage[e]},r.getPayload=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n&&3===n.split(".").length){var r=n.split(".")[1],i=r.replace("-","+").replace("_","/");return JSON.parse(t.atob(i))}},r.setToken=function(e,r){var i=e.access_token||e.data[o.tokenName],a=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;if(!i)throw new Error('Expecting a token named "'+o.tokenName+'" but instead got: '+JSON.stringify(e.data));t.localStorage[a]=i,o.loginRedirect&&!r&&n.path(o.loginRedirect)},r.removeToken=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;delete t.localStorage[e]},r.isAuthenticated=function(){var e=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName,n=t.localStorage[e];if(n){if(3===n.split(".").length){var r=n.split(".")[1],i=r.replace("-","+").replace("_","/"),a=JSON.parse(t.atob(i)).exp;return Math.round((new Date).getTime()/1e3)<=a}return!0}return!1},r.logout=function(){var r=o.tokenPrefix?o.tokenPrefix+"_"+o.tokenName:o.tokenName;return delete t.localStorage[r],o.logoutRedirect&&n.path(o.logoutRedirect),e.when()},r}]).factory("satellizer.oauth",["$q","$http","satellizer.config","satellizer.shared","satellizer.Oauth1","satellizer.Oauth2",function(e,t,n,o,r,i){var a={};return a.authenticate=function(e,t,a){var u="1.0"===n.providers[e].type?new r:new i;return u.open(n.providers[e],a||{}).then(function(e){return o.setToken(e,t),e})},a.unlink=function(e){return t.get(n.unlinkUrl+e)},a}]).factory("satellizer.local",["$q","$http","$location","satellizer.utils","satellizer.shared","satellizer.config",function(e,t,n,o,r,i){var a={};return a.login=function(e){return t.post(i.loginUrl,e).then(function(e){return r.setToken(e),e})},a.signup=function(e){return t.post(i.signupUrl,e).then(function(e){return i.loginOnSignup?r.setToken(e):i.signupRedirect&&n.path(i.signupRedirect),e})},a}]).factory("satellizer.Oauth2",["$q","$http","$window","satellizer.popup","satellizer.utils","satellizer.config",function(e,n,o,r,i){return function(){var a={url:null,name:null,state:null,scope:null,scopeDelimiter:null,clientId:null,redirectUri:null,popupOptions:null,authorizationEndpoint:null,responseParams:null,requiredUrlParams:null,optionalUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code"},u={};return u.open=function(n,i){t.extend(a,n),a.state&&(o.localStorage.state=a.state());var l=a.authorizationEndpoint+"?"+u.buildQueryString();return r.open(l,a.popupOptions).then(function(t){return t.state&&t.state!==o.localStorage.state?e.reject({data:"Invalid state parameter"}):"token"===a.responseType?t:u.exchangeForToken(t,i)})},u.exchangeForToken=function(e,o){var r=t.extend({},o,{code:e.code,clientId:a.clientId,redirectUri:a.redirectUri});return t.forEach(a.responseParams,function(t){r[t]=e[t]}),n.post(a.url,r,{withCredentials:!0})},u.buildQueryString=function(){var e=[],n=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(n,function(n){t.forEach(a[n],function(t){var n=i.camelCase(t),r=a[n];"state"===t&&(r=o.localStorage.state),"scope"===t&&Array.isArray(r)&&(r=r.join(a.scopeDelimiter),a.scopePrefix&&(r=[a.scopePrefix,r].join(a.scopeDelimiter))),e.push([t,r])})}),e.map(function(e){return e.join("=")}).join("&")},u}}]).factory("satellizer.Oauth1",["$q","$http","satellizer.popup",function(e,n,o){return function(){var e={url:null,name:null,popupOptions:null},r={};return r.open=function(n,i){return t.extend(e,n),o.open(e.url,e.popupOptions).then(function(e){return r.exchangeForToken(e,i)})},r.exchangeForToken=function(o,i){var a=t.extend({},i,o),u=r.buildQueryString(a);return n.get(e.url+"?"+u)},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,r,i,a){var u=null,l=null,c={};return c.popupWindow=u,c.open=function(t,n){var o=c.stringifyOptions(c.prepareOptions(n||{}));return u=e.open(t,"_blank",o),u&&u.focus&&u.focus(),c.pollPopup()},c.pollPopup=function(){var e=n.defer();return l=o(function(){try{if(u.document.domain===document.domain&&(u.location.search||u.location.hash)){var n=u.location.search.substring(1).replace(/\/$/,""),r=u.location.hash.substring(1).replace(/\/$/,""),i=a.parseQueryString(r),c=a.parseQueryString(n);t.extend(c,i),c.error?e.reject({error:c.error}):e.resolve(c),u.close(),o.cancel(l)}}catch(s){}u.closed&&(o.cancel(l),e.reject({data:"Authorization Failed"}))},35),e.promise},c.prepareOptions=function(e){var n=e.width||500,o=e.height||500;return t.extend({width:n,height:o,left:r.screenX+(r.outerWidth-n)/2,top:r.screenY+(r.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,r={};return t.forEach((e||"").split("&"),function(e){e&&(o=e.split("="),n=decodeURIComponent(o[0]),r[n]=t.isDefined(o[1])?decodeURIComponent(o[1]):!0)}),r}}).config(["$httpProvider","satellizer.config",function(e,t){t.httpInterceptor&&e.interceptors.push(["$q",function(e){var n=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName;return{request:function(e){var o=localStorage.getItem(n);return o&&(o="Authorization"===t.authHeader?"Bearer "+o:o,e.headers[t.authHeader]=o),e},responseError:function(t){return e.reject(t)}}}])}])}(window,window.angular),function(){function e(e){this.message=e}var t="undefined"!=typeof exports?exports:this,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.prototype=new Error,e.prototype.name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var o,r,i=String(t),a=0,u=n,l="";i.charAt(0|a)||(u="=",a%1);l+=u.charAt(63&o>>8-a%1*8)){if(r=i.charCodeAt(a+=.75),r>255)throw new e("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|r}return l}),t.atob||(t.atob=function(t){var o=String(t).replace(/=+$/,"");if(o.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,i,a=0,u=0,l="";i=o.charAt(u++);~i&&(r=a%4?64*r+i:i,a++%4)?l+=String.fromCharCode(255&r>>(-2*a&6)):0)i=n.indexOf(i);return l})}(); \ No newline at end of file