From bf3d1a507bab55e6c93149ff06ed26567b62dd05 Mon Sep 17 00:00:00 2001 From: Connor Leech Date: Thu, 14 Jan 2016 11:01:29 -0800 Subject: [PATCH 01/11] Add bower script tag Helpful for people new to bower. Include the bower script tag for copy and paste from documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7fff46db..8190acdf 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ Alternatively, you may [**download**](https://github.com/sahat/satellizer/releas ``` +If installed via bower, include the script tag `` or `` + **Note:** Sattelizer depends on [`window.atob()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob) for decoding JSON Web Tokens. If you need to support *IE9* then use Base64 polyfill above. From 8792bfe598e8fd5bffc04fb2232820fab5341cc3 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Thu, 14 Jan 2016 14:53:43 -0500 Subject: [PATCH 02/11] readme: bower getting started instructions --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8190acdf..4f8c71c6 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,7 @@ in the app *config* block. ## Installation -The easiest way to get **Satellizer** is by running one of the following -commands: +The easiest way to get **Satellizer** is by running one of the following commands: ```bash # Bower @@ -63,7 +62,13 @@ Alternatively, you may [**download**](https://github.com/sahat/satellizer/releas ``` -If installed via bower, include the script tag `` or `` +If installed via [Bower](http://bower.io/), include one of the following script tags: +``` + +``` +``` + +``` **Note:** Sattelizer depends on [`window.atob()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob) for decoding JSON Web Tokens. If you need to support *IE9* then use Base64 polyfill above. From 22a98bc8211e898a0a2192a668402cfbb4dea9c5 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Thu, 14 Jan 2016 14:55:25 -0500 Subject: [PATCH 03/11] readme: html code formatting --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f8c71c6..e09f5113 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,9 @@ Alternatively, you may [**download**](https://github.com/sahat/satellizer/releas ``` If installed via [Bower](http://bower.io/), include one of the following script tags: -``` +```html -``` -``` + ``` From aeb8fc088bb51a0bb2917e3bf3012ba97845540e Mon Sep 17 00:00:00 2001 From: Prayag Verma Date: Sat, 16 Jan 2016 14:00:34 +0530 Subject: [PATCH 04/11] Update license year to 2016 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index c655d3c8..fc66383f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2015 Sahat Yalkabov +Copyright (c) 2016 Sahat Yalkabov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 220a214f00c4c106ebf927e997774f59106fd575 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Wed, 20 Jan 2016 01:13:53 -0500 Subject: [PATCH 05/11] add comment to try/catch --- satellizer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/satellizer.js b/satellizer.js index 0a731e6d..b8e66aa2 100644 --- a/satellizer.js +++ b/satellizer.js @@ -630,7 +630,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex var serverUrl = config.baseUrl ? utils.joinUrl(config.baseUrl, defaults.url) : defaults.url; if (!config.cordova) { - popupWindow = popup.open('', defaults.name, defaults.popupOptions, defaults.redirectUri); + popupWindow = popup.open('', defaults.name, defaults.popupOptions, defaults.redirectUri); } return $http.post(serverUrl, defaults) @@ -770,6 +770,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex } } catch (error) { // Ignore DOMException: Blocked a frame with origin from accessing a cross-origin frame. + // A hack to get around same-origin security policy errors in IE. } if (!Popup.popupWindow || Popup.popupWindow.closed || Popup.popupWindow.closed === undefined) { From 62734a3a956b6e02038fb2c23a6575a4db81eaf4 Mon Sep 17 00:00:00 2001 From: Gillardo Date: Wed, 20 Jan 2016 15:10:52 +0000 Subject: [PATCH 06/11] Fixed pollPopup Popup closing when identity service and resource on same server --- satellizer.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/satellizer.js b/satellizer.js index 0a731e6d..304d0e39 100644 --- a/satellizer.js +++ b/satellizer.js @@ -519,7 +519,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex if (config.cordova) { openPopup = popup.open(url, defaults.name, defaults.popupOptions, defaults.redirectUri).eventListener(defaults.redirectUri); } else { - openPopup = popup.open(url, defaults.name, defaults.popupOptions, defaults.redirectUri).pollPopup(); + openPopup = popup.open(url, defaults.name, defaults.popupOptions, defaults.redirectUri).pollPopup(defaults.redirectUri); } return openPopup @@ -648,7 +648,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex if (config.cordova) { popupListener = popupWindow.eventListener(defaults.redirectUri); } else { - popupListener = popupWindow.pollPopup(); + popupListener = popupWindow.pollPopup(defaults.redirectUri); } return popupListener @@ -742,15 +742,16 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex return deferred.promise; }; - Popup.pollPopup = function() { + Popup.pollPopup = function(redirectUri) { var deferred = $q.defer(); var polling = $interval(function() { try { - var documentOrigin = document.location.host; - var popupWindowOrigin = Popup.popupWindow.location.host; - - if (popupWindowOrigin === documentOrigin && (Popup.popupWindow.location.search || Popup.popupWindow.location.hash)) { + var popupWindowOrigin = Popup.popupWindow.location.protocol + '//' + + Popup.popupWindow.location.host + + Popup.popupWindow.location.pathname; + + if (popupWindowOrigin === redirectUri && (Popup.popupWindow.location.search || Popup.popupWindow.location.hash)) { var queryParams = Popup.popupWindow.location.search.substring(1).replace(/\/$/, ''); var hashParams = Popup.popupWindow.location.hash.substring(1).replace(/[\/$]/, ''); var hash = utils.parseQueryString(hashParams); From a6706b05ba72970a189badee2a237b85f30417da Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Thu, 21 Jan 2016 13:24:36 -0500 Subject: [PATCH 07/11] Fixed formatting --- satellizer.js | 2 +- satellizer.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/satellizer.js b/satellizer.js index 672020aa..6a6e8947 100644 --- a/satellizer.js +++ b/satellizer.js @@ -747,7 +747,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex var polling = $interval(function() { try { - var popupWindowOrigin = Popup.popupWindow.location.protocol + '//' + + var popupWindowOrigin = Popup.popupWindow.location.protocol + '//' + Popup.popupWindow.location.host + Popup.popupWindow.location.pathname; diff --git a/satellizer.min.js b/satellizer.min.js index a49f13f8..53e38dc1 100644 --- a/satellizer.min.js +++ b/satellizer.min.js @@ -3,4 +3,4 @@ * (c) 2016 Sahat Yalkabov * License: MIT */ -"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="satellizer"),function(e,t,r){"use strict";e.location.origin||(e.location.origin=e.location.protocol+"//"+e.location.host),t.module("satellizer",[]).constant("SatellizerConfig",{httpInterceptor:function(){return!0},withCredentials:!1,tokenRoot:null,cordova:!1,baseUrl:"/",loginUrl:"/auth/login",signupUrl:"/auth/signup",unlinkUrl:"/auth/unlink/",tokenName:"token",tokenPrefix:"satellizer",authHeader:"Authorization",authToken:"Bearer",storageType:"localStorage",providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e.location.origin+"/",requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin,optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0"},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:e.location.origin,oauthType:"1.0",popupOptions:{width:495,height:645}},twitch:{name:"twitch",url:"/auth/twitch",authorizationEndpoint:"https://api.twitch.tv/kraken/oauth2/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["user_read"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin,requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},yahoo:{name:"yahoo",url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin,scope:[],scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:559,height:519}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}}}}).provider("$auth",["SatellizerConfig",function(e){Object.defineProperties(this,{httpInterceptor:{get:function(){return e.httpInterceptor},set:function(t){"function"==typeof t?e.httpInterceptor=t:e.httpInterceptor=function(){return t}}},baseUrl:{get:function(){return e.baseUrl},set:function(t){e.baseUrl=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}},tokenRoot:{get:function(){return e.tokenRoot},set:function(t){e.tokenRoot=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}},authToken:{get:function(){return e.authToken},set:function(t){e.authToken=t}},withCredentials:{get:function(){return e.withCredentials},set:function(t){e.withCredentials=t}},cordova:{get:function(){return e.cordova},set:function(t){e.cordova=t}},storageType:{get:function(){return e.storageType},set:function(t){e.storageType=t}}}),t.forEach(Object.keys(e.providers),function(r){this[r]=function(n){return t.extend(e.providers[r],n)}},this);var r=function(r){e.providers[r.name]=e.providers[r.name]||{},t.extend(e.providers[r.name],r)};this.oauth1=function(t){r(t),e.providers[t.name].oauthType="1.0"},this.oauth2=function(t){r(t),e.providers[t.name].oauthType="2.0"},this.$get=["$q","SatellizerShared","SatellizerLocal","SatellizerOauth",function(e,t,r,n){var o={};return o.login=function(e,t){return r.login(e,t)},o.signup=function(e,t){return r.signup(e,t)},o.logout=function(){return t.logout()},o.authenticate=function(e,t){return n.authenticate(e,t)},o.link=function(e,t){return n.authenticate(e,t)},o.unlink=function(e,t){return n.unlink(e,t)},o.isAuthenticated=function(){return t.isAuthenticated()},o.getToken=function(){return t.getToken()},o.setToken=function(e){t.setToken({access_token:e})},o.removeToken=function(){return t.removeToken()},o.getPayload=function(){return t.getPayload()},o.setStorageType=function(e){return t.setStorageType(e)},o}]}]).factory("SatellizerShared",["$q","$window","$log","SatellizerConfig","SatellizerStorage",function(n,o,i,a,u){var p={},l=a.tokenPrefix?[a.tokenPrefix,a.tokenName].join("_"):a.tokenName;return p.getToken=function(){return u.get(l)},p.getPayload=function(){var t=u.get(l);if(t&&3===t.split(".").length)try{var n=t.split(".")[1],o=n.replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(decodeURIComponent(escape(e.atob(o))))}catch(i){return r}},p.setToken=function(e){if(!e)return i.warn("Can't set token without passing a value");var r,n=e&&e.access_token;if(n&&(t.isObject(n)&&t.isObject(n.data)?e=n:t.isString(n)&&(r=n)),!r&&e){var o=a.tokenRoot&&a.tokenRoot.split(".").reduce(function(e,t){return e[t]},e.data);r=o?o[a.tokenName]:e.data&&e.data[a.tokenName]}if(!r){var p=a.tokenRoot?a.tokenRoot+"."+a.tokenName:a.tokenName;return i.warn('Expecting a token named "'+p)}u.set(l,r)},p.removeToken=function(){u.remove(l)},p.isAuthenticated=function(){var e=u.get(l);if(e){if(3===e.split(".").length)try{var t=e.split(".")[1],r=t.replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(o.atob(r)).exp;if(n){var i=Math.round((new Date).getTime()/1e3)>=n;return i?(u.remove(l),!1):!0}}catch(a){return!0}return!0}return!1},p.logout=function(){return u.remove(l),n.when()},p.setStorageType=function(e){a.storageType=e},p}]).factory("SatellizerOauth",["$q","$http","SatellizerConfig","SatellizerUtils","SatellizerShared","SatellizerOauth1","SatellizerOauth2",function(e,t,r,n,o,i,a){var u={};return u.authenticate=function(t,n){var u="1.0"===r.providers[t].oauthType?new i:new a,p=e.defer();return u.open(r.providers[t],n||{}).then(function(e){r.providers[t].url&&o.setToken(e,!1),p.resolve(e)})["catch"](function(e){p.reject(e)}),p.promise},u.unlink=function(e,o){return o=o||{},o.url=o.url?o.url:n.joinUrl(r.baseUrl,r.unlinkUrl),o.data={provider:e}||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||r.withCredentials,t(o)},u}]).factory("SatellizerLocal",["$http","SatellizerUtils","SatellizerShared","SatellizerConfig",function(e,t,r,n){var o={};return o.login=function(o,i){return i=i||{},i.url=i.url?i.url:t.joinUrl(n.baseUrl,n.loginUrl),i.data=o||i.data,i.method=i.method||"POST",i.withCredentials=i.withCredentials||n.withCredentials,e(i).then(function(e){return r.setToken(e),e})},o.signup=function(r,o){return o=o||{},o.url=o.url?o.url:t.joinUrl(n.baseUrl,n.signupUrl),o.data=r||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||n.withCredentials,e(o)},o}]).factory("SatellizerOauth2",["$q","$http","$window","SatellizerPopup","SatellizerUtils","SatellizerConfig","SatellizerStorage",function(e,r,n,o,i,a,u){return function(){var n={},p={defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}};return n.open=function(r,l){p=i.merge(r,p);var c,s,h=p.name+"_state";return t.isFunction(p.state)?u.set(h,p.state()):t.isString(p.state)&&u.set(h,p.state),c=[p.authorizationEndpoint,n.buildQueryString()].join("?"),s=a.cordova?o.open(c,p.name,p.popupOptions,p.redirectUri).eventListener(p.redirectUri):o.open(c,p.name,p.popupOptions,p.redirectUri).pollPopup(),s.then(function(t){return"token"!==p.responseType&&p.url?t.state&&t.state!==u.get(h)?e.reject('OAuth "state" mismatch'):n.exchangeForToken(t,l):t})},n.exchangeForToken=function(e,n){var o=t.extend({},n);t.forEach(p.responseParams,function(t,r){switch(r){case"code":o[t]=e.code;break;case"clientId":o[t]=p.clientId;break;case"redirectUri":o[t]=p.redirectUri;break;default:o[t]=e[r]}}),e.state&&(o.state=e.state);var u=a.baseUrl?i.joinUrl(a.baseUrl,p.url):p.url;return r.post(u,o,{withCredentials:a.withCredentials})},n.buildQueryString=function(){var e=[],r=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(r,function(r){t.forEach(p[r],function(r){var n=i.camelCase(r),o=t.isFunction(p[r])?p[r]():p[n];if("redirect_uri"!==r||o){if("state"===r){var a=p.name+"_state";o=encodeURIComponent(u.get(a))}"scope"===r&&Array.isArray(o)&&(o=o.join(p.scopeDelimiter),p.scopePrefix&&(o=[p.scopePrefix,o].join(p.scopeDelimiter))),e.push([r,o])}})}),e.map(function(e){return e.join("=")}).join("&")},n}}]).factory("SatellizerOauth1",["$q","$http","SatellizerPopup","SatellizerConfig","SatellizerUtils",function(e,r,n,o,i){return function(){var e={},a={url:null,name:null,popupOptions:null,redirectUri:null,authorizationEndpoint:null};return e.open=function(u,p){t.extend(a,u);var l,c=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return o.cordova||(l=n.open("",a.name,a.popupOptions,a.redirectUri)),r.post(c,a).then(function(t){var r=[a.authorizationEndpoint,e.buildQueryString(t.data)].join("?");o.cordova?l=n.open(r,a.name,a.popupOptions,a.redirectUri):l.popupWindow.location=r;var i;return i=o.cordova?l.eventListener(a.redirectUri):l.pollPopup(),i.then(function(t){return e.exchangeForToken(t,p)})})},e.exchangeForToken=function(e,n){var u=t.extend({},n,e),p=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return r.post(p,u,{withCredentials:o.withCredentials})},e.buildQueryString=function(e){var r=[];return t.forEach(e,function(e,t){r.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),r.join("&")},e}}]).factory("SatellizerPopup",["$q","$interval","$window","SatellizerConfig","SatellizerUtils",function(e,n,o,i,a){var u={};return u.url="",u.popupWindow=null,u.open=function(e,t,r){u.url=e;var n=u.stringifyOptions(u.prepareOptions(r)),a=o.navigator.userAgent,p=i.cordova||a.indexOf("CriOS")>-1?"_blank":t;return u.popupWindow=o.open(e,p,n),o.popup=u.popupWindow,u.popupWindow&&u.popupWindow.focus&&u.popupWindow.focus(),u},u.eventListener=function(r){var n=e.defer();return u.popupWindow.addEventListener("loadstart",function(e){if(0===e.url.indexOf(r)){var o=document.createElement("a");if(o.href=e.url,o.search||o.hash){var i=o.search.substring(1).replace(/\/$/,""),p=o.hash.substring(1).replace(/\/$/,""),l=a.parseQueryString(p),c=a.parseQueryString(i);t.extend(c,l),c.error||n.resolve(c),u.popupWindow.close()}}}),u.popupWindow.addEventListener("loaderror",function(){n.reject("Authorization Failed")}),n.promise},u.pollPopup=function(){var o=e.defer(),i=n(function(){try{var e=document.location.host,p=u.popupWindow.location.host;if(p===e&&(u.popupWindow.location.search||u.popupWindow.location.hash)){var l=u.popupWindow.location.search.substring(1).replace(/\/$/,""),c=u.popupWindow.location.hash.substring(1).replace(/[\/$]/,""),s=a.parseQueryString(c),h=a.parseQueryString(l);t.extend(h,s),h.error?o.reject(h):o.resolve(h),n.cancel(i),u.popupWindow.close()}}catch(d){}(!u.popupWindow||u.popupWindow.closed||u.popupWindow.closed===r)&&n.cancel(i)},20);return o.promise},u.prepareOptions=function(e){e=e||{};var r=e.width||500,n=e.height||500;return t.extend({width:r,height:n,left:o.screenX+(o.outerWidth-r)/2,top:o.screenY+(o.outerHeight-n)/2.5},e)},u.stringifyOptions=function(e){var r=[];return t.forEach(e,function(e,t){r.push(t+"="+e)}),r.join(",")},u}]).service("SatellizerUtils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,r,n){return n?r.toUpperCase():r})},this.parseQueryString=function(e){var r,n,o={};return t.forEach((e||"").split("&"),function(e){e&&(n=e.split("="),r=decodeURIComponent(n[0]),o[r]=t.isDefined(n[1])?decodeURIComponent(n[1]):!0)}),o},this.joinUrl=function(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var r=[e,t].join("/"),n=function(e){return e.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return n(r)},this.merge=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(n in t&&"object"==typeof e[n]&&null!==n?r[n]=this.merge(e[n],t[n]):r[n]=e[n]);for(n in t)if(t.hasOwnProperty(n)){if(n in r)continue;r[n]=t[n]}return r}}).factory("SatellizerStorage",["$window","$log","SatellizerConfig",function(e,t,r){var n={},o=function(){try{var t=r.storageType in e&&null!==e[r.storageType];if(t){var n=Math.random().toString(36).substring(7);e[r.storageType].setItem(n,""),e[r.storageType].removeItem(n)}return t}catch(o){return!1}}();return o||t.warn(r.storageType+" is not available."),{get:function(t){return o?e[r.storageType].getItem(t):n[t]},set:function(t,i){return o?e[r.storageType].setItem(t,i):n[t]=i},remove:function(t){return o?e[r.storageType].removeItem(t):delete n[t]}}}]).factory("SatellizerInterceptor",["$q","SatellizerConfig","SatellizerStorage","SatellizerShared",function(e,t,r,n){return{request:function(e){if(e.skipAuthorization)return e;if(n.isAuthenticated()&&t.httpInterceptor(e)){var o=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName,i=r.get(o);t.authHeader&&t.authToken&&(i=t.authToken+" "+i),e.headers[t.authHeader]=i}return e},responseError:function(t){return e.reject(t)}}}]).config(["$httpProvider",function(e){e.interceptors.push("SatellizerInterceptor")}])}(window,window.angular); \ No newline at end of file +"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="satellizer"),function(e,t,r){"use strict";e.location.origin||(e.location.origin=e.location.protocol+"//"+e.location.host),t.module("satellizer",[]).constant("SatellizerConfig",{httpInterceptor:function(){return!0},withCredentials:!1,tokenRoot:null,cordova:!1,baseUrl:"/",loginUrl:"/auth/login",signupUrl:"/auth/signup",unlinkUrl:"/auth/unlink/",tokenName:"token",tokenPrefix:"satellizer",authHeader:"Authorization",authToken:"Bearer",storageType:"localStorage",providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e.location.origin+"/",requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin,optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0"},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:e.location.origin,oauthType:"1.0",popupOptions:{width:495,height:645}},twitch:{name:"twitch",url:"/auth/twitch",authorizationEndpoint:"https://api.twitch.tv/kraken/oauth2/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["user_read"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin,requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},yahoo:{name:"yahoo",url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin,scope:[],scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:559,height:519}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}}}}).provider("$auth",["SatellizerConfig",function(e){Object.defineProperties(this,{httpInterceptor:{get:function(){return e.httpInterceptor},set:function(t){"function"==typeof t?e.httpInterceptor=t:e.httpInterceptor=function(){return t}}},baseUrl:{get:function(){return e.baseUrl},set:function(t){e.baseUrl=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}},tokenRoot:{get:function(){return e.tokenRoot},set:function(t){e.tokenRoot=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}},authToken:{get:function(){return e.authToken},set:function(t){e.authToken=t}},withCredentials:{get:function(){return e.withCredentials},set:function(t){e.withCredentials=t}},cordova:{get:function(){return e.cordova},set:function(t){e.cordova=t}},storageType:{get:function(){return e.storageType},set:function(t){e.storageType=t}}}),t.forEach(Object.keys(e.providers),function(r){this[r]=function(n){return t.extend(e.providers[r],n)}},this);var r=function(r){e.providers[r.name]=e.providers[r.name]||{},t.extend(e.providers[r.name],r)};this.oauth1=function(t){r(t),e.providers[t.name].oauthType="1.0"},this.oauth2=function(t){r(t),e.providers[t.name].oauthType="2.0"},this.$get=["$q","SatellizerShared","SatellizerLocal","SatellizerOauth",function(e,t,r,n){var o={};return o.login=function(e,t){return r.login(e,t)},o.signup=function(e,t){return r.signup(e,t)},o.logout=function(){return t.logout()},o.authenticate=function(e,t){return n.authenticate(e,t)},o.link=function(e,t){return n.authenticate(e,t)},o.unlink=function(e,t){return n.unlink(e,t)},o.isAuthenticated=function(){return t.isAuthenticated()},o.getToken=function(){return t.getToken()},o.setToken=function(e){t.setToken({access_token:e})},o.removeToken=function(){return t.removeToken()},o.getPayload=function(){return t.getPayload()},o.setStorageType=function(e){return t.setStorageType(e)},o}]}]).factory("SatellizerShared",["$q","$window","$log","SatellizerConfig","SatellizerStorage",function(n,o,i,a,u){var p={},l=a.tokenPrefix?[a.tokenPrefix,a.tokenName].join("_"):a.tokenName;return p.getToken=function(){return u.get(l)},p.getPayload=function(){var t=u.get(l);if(t&&3===t.split(".").length)try{var n=t.split(".")[1],o=n.replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(decodeURIComponent(escape(e.atob(o))))}catch(i){return r}},p.setToken=function(e){if(!e)return i.warn("Can't set token without passing a value");var r,n=e&&e.access_token;if(n&&(t.isObject(n)&&t.isObject(n.data)?e=n:t.isString(n)&&(r=n)),!r&&e){var o=a.tokenRoot&&a.tokenRoot.split(".").reduce(function(e,t){return e[t]},e.data);r=o?o[a.tokenName]:e.data&&e.data[a.tokenName]}if(!r){var p=a.tokenRoot?a.tokenRoot+"."+a.tokenName:a.tokenName;return i.warn('Expecting a token named "'+p)}u.set(l,r)},p.removeToken=function(){u.remove(l)},p.isAuthenticated=function(){var e=u.get(l);if(e){if(3===e.split(".").length)try{var t=e.split(".")[1],r=t.replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(o.atob(r)).exp;if(n){var i=Math.round((new Date).getTime()/1e3)>=n;return i?(u.remove(l),!1):!0}}catch(a){return!0}return!0}return!1},p.logout=function(){return u.remove(l),n.when()},p.setStorageType=function(e){a.storageType=e},p}]).factory("SatellizerOauth",["$q","$http","SatellizerConfig","SatellizerUtils","SatellizerShared","SatellizerOauth1","SatellizerOauth2",function(e,t,r,n,o,i,a){var u={};return u.authenticate=function(t,n){var u="1.0"===r.providers[t].oauthType?new i:new a,p=e.defer();return u.open(r.providers[t],n||{}).then(function(e){r.providers[t].url&&o.setToken(e,!1),p.resolve(e)})["catch"](function(e){p.reject(e)}),p.promise},u.unlink=function(e,o){return o=o||{},o.url=o.url?o.url:n.joinUrl(r.baseUrl,r.unlinkUrl),o.data={provider:e}||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||r.withCredentials,t(o)},u}]).factory("SatellizerLocal",["$http","SatellizerUtils","SatellizerShared","SatellizerConfig",function(e,t,r,n){var o={};return o.login=function(o,i){return i=i||{},i.url=i.url?i.url:t.joinUrl(n.baseUrl,n.loginUrl),i.data=o||i.data,i.method=i.method||"POST",i.withCredentials=i.withCredentials||n.withCredentials,e(i).then(function(e){return r.setToken(e),e})},o.signup=function(r,o){return o=o||{},o.url=o.url?o.url:t.joinUrl(n.baseUrl,n.signupUrl),o.data=r||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||n.withCredentials,e(o)},o}]).factory("SatellizerOauth2",["$q","$http","$window","SatellizerPopup","SatellizerUtils","SatellizerConfig","SatellizerStorage",function(e,r,n,o,i,a,u){return function(){var n={},p={defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}};return n.open=function(r,l){p=i.merge(r,p);var c,s,h=p.name+"_state";return t.isFunction(p.state)?u.set(h,p.state()):t.isString(p.state)&&u.set(h,p.state),c=[p.authorizationEndpoint,n.buildQueryString()].join("?"),s=a.cordova?o.open(c,p.name,p.popupOptions,p.redirectUri).eventListener(p.redirectUri):o.open(c,p.name,p.popupOptions,p.redirectUri).pollPopup(p.redirectUri),s.then(function(t){return"token"!==p.responseType&&p.url?t.state&&t.state!==u.get(h)?e.reject('OAuth "state" mismatch'):n.exchangeForToken(t,l):t})},n.exchangeForToken=function(e,n){var o=t.extend({},n);t.forEach(p.responseParams,function(t,r){switch(r){case"code":o[t]=e.code;break;case"clientId":o[t]=p.clientId;break;case"redirectUri":o[t]=p.redirectUri;break;default:o[t]=e[r]}}),e.state&&(o.state=e.state);var u=a.baseUrl?i.joinUrl(a.baseUrl,p.url):p.url;return r.post(u,o,{withCredentials:a.withCredentials})},n.buildQueryString=function(){var e=[],r=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(r,function(r){t.forEach(p[r],function(r){var n=i.camelCase(r),o=t.isFunction(p[r])?p[r]():p[n];if("redirect_uri"!==r||o){if("state"===r){var a=p.name+"_state";o=encodeURIComponent(u.get(a))}"scope"===r&&Array.isArray(o)&&(o=o.join(p.scopeDelimiter),p.scopePrefix&&(o=[p.scopePrefix,o].join(p.scopeDelimiter))),e.push([r,o])}})}),e.map(function(e){return e.join("=")}).join("&")},n}}]).factory("SatellizerOauth1",["$q","$http","SatellizerPopup","SatellizerConfig","SatellizerUtils",function(e,r,n,o,i){return function(){var e={},a={url:null,name:null,popupOptions:null,redirectUri:null,authorizationEndpoint:null};return e.open=function(u,p){t.extend(a,u);var l,c=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return o.cordova||(l=n.open("",a.name,a.popupOptions,a.redirectUri)),r.post(c,a).then(function(t){var r=[a.authorizationEndpoint,e.buildQueryString(t.data)].join("?");o.cordova?l=n.open(r,a.name,a.popupOptions,a.redirectUri):l.popupWindow.location=r;var i;return i=o.cordova?l.eventListener(a.redirectUri):l.pollPopup(a.redirectUri),i.then(function(t){return e.exchangeForToken(t,p)})})},e.exchangeForToken=function(e,n){var u=t.extend({},n,e),p=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return r.post(p,u,{withCredentials:o.withCredentials})},e.buildQueryString=function(e){var r=[];return t.forEach(e,function(e,t){r.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),r.join("&")},e}}]).factory("SatellizerPopup",["$q","$interval","$window","SatellizerConfig","SatellizerUtils",function(e,n,o,i,a){var u={};return u.url="",u.popupWindow=null,u.open=function(e,t,r){u.url=e;var n=u.stringifyOptions(u.prepareOptions(r)),a=o.navigator.userAgent,p=i.cordova||a.indexOf("CriOS")>-1?"_blank":t;return u.popupWindow=o.open(e,p,n),o.popup=u.popupWindow,u.popupWindow&&u.popupWindow.focus&&u.popupWindow.focus(),u},u.eventListener=function(r){var n=e.defer();return u.popupWindow.addEventListener("loadstart",function(e){if(0===e.url.indexOf(r)){var o=document.createElement("a");if(o.href=e.url,o.search||o.hash){var i=o.search.substring(1).replace(/\/$/,""),p=o.hash.substring(1).replace(/\/$/,""),l=a.parseQueryString(p),c=a.parseQueryString(i);t.extend(c,l),c.error||n.resolve(c),u.popupWindow.close()}}}),u.popupWindow.addEventListener("loaderror",function(){n.reject("Authorization Failed")}),n.promise},u.pollPopup=function(o){var i=e.defer(),p=n(function(){try{var e=u.popupWindow.location.protocol+"//"+u.popupWindow.location.host+u.popupWindow.location.pathname;if(e===o&&(u.popupWindow.location.search||u.popupWindow.location.hash)){var l=u.popupWindow.location.search.substring(1).replace(/\/$/,""),c=u.popupWindow.location.hash.substring(1).replace(/[\/$]/,""),s=a.parseQueryString(c),h=a.parseQueryString(l);t.extend(h,s),h.error?i.reject(h):i.resolve(h),n.cancel(p),u.popupWindow.close()}}catch(d){}(!u.popupWindow||u.popupWindow.closed||u.popupWindow.closed===r)&&n.cancel(p)},20);return i.promise},u.prepareOptions=function(e){e=e||{};var r=e.width||500,n=e.height||500;return t.extend({width:r,height:n,left:o.screenX+(o.outerWidth-r)/2,top:o.screenY+(o.outerHeight-n)/2.5},e)},u.stringifyOptions=function(e){var r=[];return t.forEach(e,function(e,t){r.push(t+"="+e)}),r.join(",")},u}]).service("SatellizerUtils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,r,n){return n?r.toUpperCase():r})},this.parseQueryString=function(e){var r,n,o={};return t.forEach((e||"").split("&"),function(e){e&&(n=e.split("="),r=decodeURIComponent(n[0]),o[r]=t.isDefined(n[1])?decodeURIComponent(n[1]):!0)}),o},this.joinUrl=function(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var r=[e,t].join("/"),n=function(e){return e.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return n(r)},this.merge=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(n in t&&"object"==typeof e[n]&&null!==n?r[n]=this.merge(e[n],t[n]):r[n]=e[n]);for(n in t)if(t.hasOwnProperty(n)){if(n in r)continue;r[n]=t[n]}return r}}).factory("SatellizerStorage",["$window","$log","SatellizerConfig",function(e,t,r){var n={},o=function(){try{var t=r.storageType in e&&null!==e[r.storageType];if(t){var n=Math.random().toString(36).substring(7);e[r.storageType].setItem(n,""),e[r.storageType].removeItem(n)}return t}catch(o){return!1}}();return o||t.warn(r.storageType+" is not available."),{get:function(t){return o?e[r.storageType].getItem(t):n[t]},set:function(t,i){return o?e[r.storageType].setItem(t,i):n[t]=i},remove:function(t){return o?e[r.storageType].removeItem(t):delete n[t]}}}]).factory("SatellizerInterceptor",["$q","SatellizerConfig","SatellizerStorage","SatellizerShared",function(e,t,r,n){return{request:function(e){if(e.skipAuthorization)return e;if(n.isAuthenticated()&&t.httpInterceptor(e)){var o=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName,i=r.get(o);t.authHeader&&t.authToken&&(i=t.authToken+" "+i),e.headers[t.authHeader]=i}return e},responseError:function(t){return e.reject(t)}}}]).config(["$httpProvider",function(e){e.interceptors.push("SatellizerInterceptor")}])}(window,window.angular); \ No newline at end of file From 1ed0bfe788db9056e2d85382ab2858c63c2db751 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 1 Feb 2016 23:06:11 -0500 Subject: [PATCH 08/11] chore(package): update dependencies http://greenkeeper.io/ --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f90707c9..42cffce4 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,12 @@ "gulp-complexity": "~0.3.2", "gulp-plumber": "^1.0.1", "gulp-rename": "^1.2.2", - "gulp-uglify": "~1.4.2", + "gulp-uglify": "~1.5.1", "gulp-header": "~1.7.1", "karma": "^0.13.11", "karma-coverage": "^0.5.2", "karma-jasmine": "^0.3.6", - "karma-phantomjs-launcher": "^0.2.1" + "karma-phantomjs-launcher": "^1.0.0" }, "license": "MIT", "tags": [ From 8a26ea635d4f75b597c431b3b2c93b49c346989e Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Tue, 2 Feb 2016 01:06:16 -0500 Subject: [PATCH 09/11] readme: fixed broken android image icon --- examples/ionic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ionic/README.md b/examples/ionic/README.md index 544720f4..72baf8b9 100644 --- a/examples/ionic/README.md +++ b/examples/ionic/README.md @@ -11,7 +11,7 @@ Ionic is the beautiful, open source front-end SDK for developing hybrid mobile a 5. **iOS** - `ionic build ios` - `ionic emulate ios` -6. **Android** +6. **Android** - `ionic platform add android` - `ionic build android` - `ionic emulate android` From a2cff15e9cb38566df80c8b91474ce55c5acedde Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Wed, 3 Feb 2016 21:30:08 -0500 Subject: [PATCH 10/11] Use location.origin when comparing popup url vs redirectUri --- satellizer.js | 8 +++----- satellizer.min.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/satellizer.js b/satellizer.js index 6a6e8947..994c2f88 100644 --- a/satellizer.js +++ b/satellizer.js @@ -555,7 +555,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex data[value] = defaults.redirectUri; break; default: - data[value] = oauthData[key] + data[value] = oauthData[key]; } }); @@ -747,10 +747,8 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex var polling = $interval(function() { try { - var popupWindowOrigin = Popup.popupWindow.location.protocol + '//' + - Popup.popupWindow.location.host + - Popup.popupWindow.location.pathname; - + var popupWindowOrigin = Popup.popupWindow.location.origin; + if (popupWindowOrigin === redirectUri && (Popup.popupWindow.location.search || Popup.popupWindow.location.hash)) { var queryParams = Popup.popupWindow.location.search.substring(1).replace(/\/$/, ''); var hashParams = Popup.popupWindow.location.hash.substring(1).replace(/[\/$]/, ''); diff --git a/satellizer.min.js b/satellizer.min.js index 53e38dc1..5f185f06 100644 --- a/satellizer.min.js +++ b/satellizer.min.js @@ -3,4 +3,4 @@ * (c) 2016 Sahat Yalkabov * License: MIT */ -"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="satellizer"),function(e,t,r){"use strict";e.location.origin||(e.location.origin=e.location.protocol+"//"+e.location.host),t.module("satellizer",[]).constant("SatellizerConfig",{httpInterceptor:function(){return!0},withCredentials:!1,tokenRoot:null,cordova:!1,baseUrl:"/",loginUrl:"/auth/login",signupUrl:"/auth/signup",unlinkUrl:"/auth/unlink/",tokenName:"token",tokenPrefix:"satellizer",authHeader:"Authorization",authToken:"Bearer",storageType:"localStorage",providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e.location.origin+"/",requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin,optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0"},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:e.location.origin,oauthType:"1.0",popupOptions:{width:495,height:645}},twitch:{name:"twitch",url:"/auth/twitch",authorizationEndpoint:"https://api.twitch.tv/kraken/oauth2/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["user_read"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin,requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},yahoo:{name:"yahoo",url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin,scope:[],scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:559,height:519}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}}}}).provider("$auth",["SatellizerConfig",function(e){Object.defineProperties(this,{httpInterceptor:{get:function(){return e.httpInterceptor},set:function(t){"function"==typeof t?e.httpInterceptor=t:e.httpInterceptor=function(){return t}}},baseUrl:{get:function(){return e.baseUrl},set:function(t){e.baseUrl=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}},tokenRoot:{get:function(){return e.tokenRoot},set:function(t){e.tokenRoot=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}},authToken:{get:function(){return e.authToken},set:function(t){e.authToken=t}},withCredentials:{get:function(){return e.withCredentials},set:function(t){e.withCredentials=t}},cordova:{get:function(){return e.cordova},set:function(t){e.cordova=t}},storageType:{get:function(){return e.storageType},set:function(t){e.storageType=t}}}),t.forEach(Object.keys(e.providers),function(r){this[r]=function(n){return t.extend(e.providers[r],n)}},this);var r=function(r){e.providers[r.name]=e.providers[r.name]||{},t.extend(e.providers[r.name],r)};this.oauth1=function(t){r(t),e.providers[t.name].oauthType="1.0"},this.oauth2=function(t){r(t),e.providers[t.name].oauthType="2.0"},this.$get=["$q","SatellizerShared","SatellizerLocal","SatellizerOauth",function(e,t,r,n){var o={};return o.login=function(e,t){return r.login(e,t)},o.signup=function(e,t){return r.signup(e,t)},o.logout=function(){return t.logout()},o.authenticate=function(e,t){return n.authenticate(e,t)},o.link=function(e,t){return n.authenticate(e,t)},o.unlink=function(e,t){return n.unlink(e,t)},o.isAuthenticated=function(){return t.isAuthenticated()},o.getToken=function(){return t.getToken()},o.setToken=function(e){t.setToken({access_token:e})},o.removeToken=function(){return t.removeToken()},o.getPayload=function(){return t.getPayload()},o.setStorageType=function(e){return t.setStorageType(e)},o}]}]).factory("SatellizerShared",["$q","$window","$log","SatellizerConfig","SatellizerStorage",function(n,o,i,a,u){var p={},l=a.tokenPrefix?[a.tokenPrefix,a.tokenName].join("_"):a.tokenName;return p.getToken=function(){return u.get(l)},p.getPayload=function(){var t=u.get(l);if(t&&3===t.split(".").length)try{var n=t.split(".")[1],o=n.replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(decodeURIComponent(escape(e.atob(o))))}catch(i){return r}},p.setToken=function(e){if(!e)return i.warn("Can't set token without passing a value");var r,n=e&&e.access_token;if(n&&(t.isObject(n)&&t.isObject(n.data)?e=n:t.isString(n)&&(r=n)),!r&&e){var o=a.tokenRoot&&a.tokenRoot.split(".").reduce(function(e,t){return e[t]},e.data);r=o?o[a.tokenName]:e.data&&e.data[a.tokenName]}if(!r){var p=a.tokenRoot?a.tokenRoot+"."+a.tokenName:a.tokenName;return i.warn('Expecting a token named "'+p)}u.set(l,r)},p.removeToken=function(){u.remove(l)},p.isAuthenticated=function(){var e=u.get(l);if(e){if(3===e.split(".").length)try{var t=e.split(".")[1],r=t.replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(o.atob(r)).exp;if(n){var i=Math.round((new Date).getTime()/1e3)>=n;return i?(u.remove(l),!1):!0}}catch(a){return!0}return!0}return!1},p.logout=function(){return u.remove(l),n.when()},p.setStorageType=function(e){a.storageType=e},p}]).factory("SatellizerOauth",["$q","$http","SatellizerConfig","SatellizerUtils","SatellizerShared","SatellizerOauth1","SatellizerOauth2",function(e,t,r,n,o,i,a){var u={};return u.authenticate=function(t,n){var u="1.0"===r.providers[t].oauthType?new i:new a,p=e.defer();return u.open(r.providers[t],n||{}).then(function(e){r.providers[t].url&&o.setToken(e,!1),p.resolve(e)})["catch"](function(e){p.reject(e)}),p.promise},u.unlink=function(e,o){return o=o||{},o.url=o.url?o.url:n.joinUrl(r.baseUrl,r.unlinkUrl),o.data={provider:e}||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||r.withCredentials,t(o)},u}]).factory("SatellizerLocal",["$http","SatellizerUtils","SatellizerShared","SatellizerConfig",function(e,t,r,n){var o={};return o.login=function(o,i){return i=i||{},i.url=i.url?i.url:t.joinUrl(n.baseUrl,n.loginUrl),i.data=o||i.data,i.method=i.method||"POST",i.withCredentials=i.withCredentials||n.withCredentials,e(i).then(function(e){return r.setToken(e),e})},o.signup=function(r,o){return o=o||{},o.url=o.url?o.url:t.joinUrl(n.baseUrl,n.signupUrl),o.data=r||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||n.withCredentials,e(o)},o}]).factory("SatellizerOauth2",["$q","$http","$window","SatellizerPopup","SatellizerUtils","SatellizerConfig","SatellizerStorage",function(e,r,n,o,i,a,u){return function(){var n={},p={defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}};return n.open=function(r,l){p=i.merge(r,p);var c,s,h=p.name+"_state";return t.isFunction(p.state)?u.set(h,p.state()):t.isString(p.state)&&u.set(h,p.state),c=[p.authorizationEndpoint,n.buildQueryString()].join("?"),s=a.cordova?o.open(c,p.name,p.popupOptions,p.redirectUri).eventListener(p.redirectUri):o.open(c,p.name,p.popupOptions,p.redirectUri).pollPopup(p.redirectUri),s.then(function(t){return"token"!==p.responseType&&p.url?t.state&&t.state!==u.get(h)?e.reject('OAuth "state" mismatch'):n.exchangeForToken(t,l):t})},n.exchangeForToken=function(e,n){var o=t.extend({},n);t.forEach(p.responseParams,function(t,r){switch(r){case"code":o[t]=e.code;break;case"clientId":o[t]=p.clientId;break;case"redirectUri":o[t]=p.redirectUri;break;default:o[t]=e[r]}}),e.state&&(o.state=e.state);var u=a.baseUrl?i.joinUrl(a.baseUrl,p.url):p.url;return r.post(u,o,{withCredentials:a.withCredentials})},n.buildQueryString=function(){var e=[],r=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(r,function(r){t.forEach(p[r],function(r){var n=i.camelCase(r),o=t.isFunction(p[r])?p[r]():p[n];if("redirect_uri"!==r||o){if("state"===r){var a=p.name+"_state";o=encodeURIComponent(u.get(a))}"scope"===r&&Array.isArray(o)&&(o=o.join(p.scopeDelimiter),p.scopePrefix&&(o=[p.scopePrefix,o].join(p.scopeDelimiter))),e.push([r,o])}})}),e.map(function(e){return e.join("=")}).join("&")},n}}]).factory("SatellizerOauth1",["$q","$http","SatellizerPopup","SatellizerConfig","SatellizerUtils",function(e,r,n,o,i){return function(){var e={},a={url:null,name:null,popupOptions:null,redirectUri:null,authorizationEndpoint:null};return e.open=function(u,p){t.extend(a,u);var l,c=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return o.cordova||(l=n.open("",a.name,a.popupOptions,a.redirectUri)),r.post(c,a).then(function(t){var r=[a.authorizationEndpoint,e.buildQueryString(t.data)].join("?");o.cordova?l=n.open(r,a.name,a.popupOptions,a.redirectUri):l.popupWindow.location=r;var i;return i=o.cordova?l.eventListener(a.redirectUri):l.pollPopup(a.redirectUri),i.then(function(t){return e.exchangeForToken(t,p)})})},e.exchangeForToken=function(e,n){var u=t.extend({},n,e),p=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return r.post(p,u,{withCredentials:o.withCredentials})},e.buildQueryString=function(e){var r=[];return t.forEach(e,function(e,t){r.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),r.join("&")},e}}]).factory("SatellizerPopup",["$q","$interval","$window","SatellizerConfig","SatellizerUtils",function(e,n,o,i,a){var u={};return u.url="",u.popupWindow=null,u.open=function(e,t,r){u.url=e;var n=u.stringifyOptions(u.prepareOptions(r)),a=o.navigator.userAgent,p=i.cordova||a.indexOf("CriOS")>-1?"_blank":t;return u.popupWindow=o.open(e,p,n),o.popup=u.popupWindow,u.popupWindow&&u.popupWindow.focus&&u.popupWindow.focus(),u},u.eventListener=function(r){var n=e.defer();return u.popupWindow.addEventListener("loadstart",function(e){if(0===e.url.indexOf(r)){var o=document.createElement("a");if(o.href=e.url,o.search||o.hash){var i=o.search.substring(1).replace(/\/$/,""),p=o.hash.substring(1).replace(/\/$/,""),l=a.parseQueryString(p),c=a.parseQueryString(i);t.extend(c,l),c.error||n.resolve(c),u.popupWindow.close()}}}),u.popupWindow.addEventListener("loaderror",function(){n.reject("Authorization Failed")}),n.promise},u.pollPopup=function(o){var i=e.defer(),p=n(function(){try{var e=u.popupWindow.location.protocol+"//"+u.popupWindow.location.host+u.popupWindow.location.pathname;if(e===o&&(u.popupWindow.location.search||u.popupWindow.location.hash)){var l=u.popupWindow.location.search.substring(1).replace(/\/$/,""),c=u.popupWindow.location.hash.substring(1).replace(/[\/$]/,""),s=a.parseQueryString(c),h=a.parseQueryString(l);t.extend(h,s),h.error?i.reject(h):i.resolve(h),n.cancel(p),u.popupWindow.close()}}catch(d){}(!u.popupWindow||u.popupWindow.closed||u.popupWindow.closed===r)&&n.cancel(p)},20);return i.promise},u.prepareOptions=function(e){e=e||{};var r=e.width||500,n=e.height||500;return t.extend({width:r,height:n,left:o.screenX+(o.outerWidth-r)/2,top:o.screenY+(o.outerHeight-n)/2.5},e)},u.stringifyOptions=function(e){var r=[];return t.forEach(e,function(e,t){r.push(t+"="+e)}),r.join(",")},u}]).service("SatellizerUtils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,r,n){return n?r.toUpperCase():r})},this.parseQueryString=function(e){var r,n,o={};return t.forEach((e||"").split("&"),function(e){e&&(n=e.split("="),r=decodeURIComponent(n[0]),o[r]=t.isDefined(n[1])?decodeURIComponent(n[1]):!0)}),o},this.joinUrl=function(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var r=[e,t].join("/"),n=function(e){return e.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return n(r)},this.merge=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(n in t&&"object"==typeof e[n]&&null!==n?r[n]=this.merge(e[n],t[n]):r[n]=e[n]);for(n in t)if(t.hasOwnProperty(n)){if(n in r)continue;r[n]=t[n]}return r}}).factory("SatellizerStorage",["$window","$log","SatellizerConfig",function(e,t,r){var n={},o=function(){try{var t=r.storageType in e&&null!==e[r.storageType];if(t){var n=Math.random().toString(36).substring(7);e[r.storageType].setItem(n,""),e[r.storageType].removeItem(n)}return t}catch(o){return!1}}();return o||t.warn(r.storageType+" is not available."),{get:function(t){return o?e[r.storageType].getItem(t):n[t]},set:function(t,i){return o?e[r.storageType].setItem(t,i):n[t]=i},remove:function(t){return o?e[r.storageType].removeItem(t):delete n[t]}}}]).factory("SatellizerInterceptor",["$q","SatellizerConfig","SatellizerStorage","SatellizerShared",function(e,t,r,n){return{request:function(e){if(e.skipAuthorization)return e;if(n.isAuthenticated()&&t.httpInterceptor(e)){var o=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName,i=r.get(o);t.authHeader&&t.authToken&&(i=t.authToken+" "+i),e.headers[t.authHeader]=i}return e},responseError:function(t){return e.reject(t)}}}]).config(["$httpProvider",function(e){e.interceptors.push("SatellizerInterceptor")}])}(window,window.angular); \ No newline at end of file +"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="satellizer"),function(e,t,r){"use strict";e.location.origin||(e.location.origin=e.location.protocol+"//"+e.location.host),t.module("satellizer",[]).constant("SatellizerConfig",{httpInterceptor:function(){return!0},withCredentials:!1,tokenRoot:null,cordova:!1,baseUrl:"/",loginUrl:"/auth/login",signupUrl:"/auth/signup",unlinkUrl:"/auth/unlink/",tokenName:"token",tokenPrefix:"satellizer",authHeader:"Authorization",authToken:"Bearer",storageType:"localStorage",providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e.location.origin+"/",requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:e.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:e.location.origin,optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0"},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/uas/oauth2/authorization",redirectUri:e.location.origin,requiredUrlParams:["state"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:e.location.origin,oauthType:"1.0",popupOptions:{width:495,height:645}},twitch:{name:"twitch",url:"/auth/twitch",authorizationEndpoint:"https://api.twitch.tv/kraken/oauth2/authorize",redirectUri:e.location.origin,requiredUrlParams:["scope"],scope:["user_read"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:e.location.origin,requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},yahoo:{name:"yahoo",url:"/auth/yahoo",authorizationEndpoint:"https://api.login.yahoo.com/oauth2/request_auth",redirectUri:e.location.origin,scope:[],scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:559,height:519}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}}}}).provider("$auth",["SatellizerConfig",function(e){Object.defineProperties(this,{httpInterceptor:{get:function(){return e.httpInterceptor},set:function(t){"function"==typeof t?e.httpInterceptor=t:e.httpInterceptor=function(){return t}}},baseUrl:{get:function(){return e.baseUrl},set:function(t){e.baseUrl=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}},tokenRoot:{get:function(){return e.tokenRoot},set:function(t){e.tokenRoot=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}},authToken:{get:function(){return e.authToken},set:function(t){e.authToken=t}},withCredentials:{get:function(){return e.withCredentials},set:function(t){e.withCredentials=t}},cordova:{get:function(){return e.cordova},set:function(t){e.cordova=t}},storageType:{get:function(){return e.storageType},set:function(t){e.storageType=t}}}),t.forEach(Object.keys(e.providers),function(r){this[r]=function(n){return t.extend(e.providers[r],n)}},this);var r=function(r){e.providers[r.name]=e.providers[r.name]||{},t.extend(e.providers[r.name],r)};this.oauth1=function(t){r(t),e.providers[t.name].oauthType="1.0"},this.oauth2=function(t){r(t),e.providers[t.name].oauthType="2.0"},this.$get=["$q","SatellizerShared","SatellizerLocal","SatellizerOauth",function(e,t,r,n){var o={};return o.login=function(e,t){return r.login(e,t)},o.signup=function(e,t){return r.signup(e,t)},o.logout=function(){return t.logout()},o.authenticate=function(e,t){return n.authenticate(e,t)},o.link=function(e,t){return n.authenticate(e,t)},o.unlink=function(e,t){return n.unlink(e,t)},o.isAuthenticated=function(){return t.isAuthenticated()},o.getToken=function(){return t.getToken()},o.setToken=function(e){t.setToken({access_token:e})},o.removeToken=function(){return t.removeToken()},o.getPayload=function(){return t.getPayload()},o.setStorageType=function(e){return t.setStorageType(e)},o}]}]).factory("SatellizerShared",["$q","$window","$log","SatellizerConfig","SatellizerStorage",function(n,o,i,a,u){var p={},l=a.tokenPrefix?[a.tokenPrefix,a.tokenName].join("_"):a.tokenName;return p.getToken=function(){return u.get(l)},p.getPayload=function(){var t=u.get(l);if(t&&3===t.split(".").length)try{var n=t.split(".")[1],o=n.replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(decodeURIComponent(escape(e.atob(o))))}catch(i){return r}},p.setToken=function(e){if(!e)return i.warn("Can't set token without passing a value");var r,n=e&&e.access_token;if(n&&(t.isObject(n)&&t.isObject(n.data)?e=n:t.isString(n)&&(r=n)),!r&&e){var o=a.tokenRoot&&a.tokenRoot.split(".").reduce(function(e,t){return e[t]},e.data);r=o?o[a.tokenName]:e.data&&e.data[a.tokenName]}if(!r){var p=a.tokenRoot?a.tokenRoot+"."+a.tokenName:a.tokenName;return i.warn('Expecting a token named "'+p)}u.set(l,r)},p.removeToken=function(){u.remove(l)},p.isAuthenticated=function(){var e=u.get(l);if(e){if(3===e.split(".").length)try{var t=e.split(".")[1],r=t.replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(o.atob(r)).exp;if(n){var i=Math.round((new Date).getTime()/1e3)>=n;return i?(u.remove(l),!1):!0}}catch(a){return!0}return!0}return!1},p.logout=function(){return u.remove(l),n.when()},p.setStorageType=function(e){a.storageType=e},p}]).factory("SatellizerOauth",["$q","$http","SatellizerConfig","SatellizerUtils","SatellizerShared","SatellizerOauth1","SatellizerOauth2",function(e,t,r,n,o,i,a){var u={};return u.authenticate=function(t,n){var u="1.0"===r.providers[t].oauthType?new i:new a,p=e.defer();return u.open(r.providers[t],n||{}).then(function(e){r.providers[t].url&&o.setToken(e,!1),p.resolve(e)})["catch"](function(e){p.reject(e)}),p.promise},u.unlink=function(e,o){return o=o||{},o.url=o.url?o.url:n.joinUrl(r.baseUrl,r.unlinkUrl),o.data={provider:e}||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||r.withCredentials,t(o)},u}]).factory("SatellizerLocal",["$http","SatellizerUtils","SatellizerShared","SatellizerConfig",function(e,t,r,n){var o={};return o.login=function(o,i){return i=i||{},i.url=i.url?i.url:t.joinUrl(n.baseUrl,n.loginUrl),i.data=o||i.data,i.method=i.method||"POST",i.withCredentials=i.withCredentials||n.withCredentials,e(i).then(function(e){return r.setToken(e),e})},o.signup=function(r,o){return o=o||{},o.url=o.url?o.url:t.joinUrl(n.baseUrl,n.signupUrl),o.data=r||o.data,o.method=o.method||"POST",o.withCredentials=o.withCredentials||n.withCredentials,e(o)},o}]).factory("SatellizerOauth2",["$q","$http","$window","SatellizerPopup","SatellizerUtils","SatellizerConfig","SatellizerStorage",function(e,r,n,o,i,a,u){return function(){var n={},p={defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}};return n.open=function(r,l){p=i.merge(r,p);var c,s,h=p.name+"_state";return t.isFunction(p.state)?u.set(h,p.state()):t.isString(p.state)&&u.set(h,p.state),c=[p.authorizationEndpoint,n.buildQueryString()].join("?"),s=a.cordova?o.open(c,p.name,p.popupOptions,p.redirectUri).eventListener(p.redirectUri):o.open(c,p.name,p.popupOptions,p.redirectUri).pollPopup(p.redirectUri),s.then(function(t){return"token"!==p.responseType&&p.url?t.state&&t.state!==u.get(h)?e.reject('OAuth "state" mismatch'):n.exchangeForToken(t,l):t})},n.exchangeForToken=function(e,n){var o=t.extend({},n);t.forEach(p.responseParams,function(t,r){switch(r){case"code":o[t]=e.code;break;case"clientId":o[t]=p.clientId;break;case"redirectUri":o[t]=p.redirectUri;break;default:o[t]=e[r]}}),e.state&&(o.state=e.state);var u=a.baseUrl?i.joinUrl(a.baseUrl,p.url):p.url;return r.post(u,o,{withCredentials:a.withCredentials})},n.buildQueryString=function(){var e=[],r=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];return t.forEach(r,function(r){t.forEach(p[r],function(r){var n=i.camelCase(r),o=t.isFunction(p[r])?p[r]():p[n];if("redirect_uri"!==r||o){if("state"===r){var a=p.name+"_state";o=encodeURIComponent(u.get(a))}"scope"===r&&Array.isArray(o)&&(o=o.join(p.scopeDelimiter),p.scopePrefix&&(o=[p.scopePrefix,o].join(p.scopeDelimiter))),e.push([r,o])}})}),e.map(function(e){return e.join("=")}).join("&")},n}}]).factory("SatellizerOauth1",["$q","$http","SatellizerPopup","SatellizerConfig","SatellizerUtils",function(e,r,n,o,i){return function(){var e={},a={url:null,name:null,popupOptions:null,redirectUri:null,authorizationEndpoint:null};return e.open=function(u,p){t.extend(a,u);var l,c=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return o.cordova||(l=n.open("",a.name,a.popupOptions,a.redirectUri)),r.post(c,a).then(function(t){var r=[a.authorizationEndpoint,e.buildQueryString(t.data)].join("?");o.cordova?l=n.open(r,a.name,a.popupOptions,a.redirectUri):l.popupWindow.location=r;var i;return i=o.cordova?l.eventListener(a.redirectUri):l.pollPopup(a.redirectUri),i.then(function(t){return e.exchangeForToken(t,p)})})},e.exchangeForToken=function(e,n){var u=t.extend({},n,e),p=o.baseUrl?i.joinUrl(o.baseUrl,a.url):a.url;return r.post(p,u,{withCredentials:o.withCredentials})},e.buildQueryString=function(e){var r=[];return t.forEach(e,function(e,t){r.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}),r.join("&")},e}}]).factory("SatellizerPopup",["$q","$interval","$window","SatellizerConfig","SatellizerUtils",function(e,n,o,i,a){var u={};return u.url="",u.popupWindow=null,u.open=function(e,t,r){u.url=e;var n=u.stringifyOptions(u.prepareOptions(r)),a=o.navigator.userAgent,p=i.cordova||a.indexOf("CriOS")>-1?"_blank":t;return u.popupWindow=o.open(e,p,n),o.popup=u.popupWindow,u.popupWindow&&u.popupWindow.focus&&u.popupWindow.focus(),u},u.eventListener=function(r){var n=e.defer();return u.popupWindow.addEventListener("loadstart",function(e){if(0===e.url.indexOf(r)){var o=document.createElement("a");if(o.href=e.url,o.search||o.hash){var i=o.search.substring(1).replace(/\/$/,""),p=o.hash.substring(1).replace(/\/$/,""),l=a.parseQueryString(p),c=a.parseQueryString(i);t.extend(c,l),c.error||n.resolve(c),u.popupWindow.close()}}}),u.popupWindow.addEventListener("loaderror",function(){n.reject("Authorization Failed")}),n.promise},u.pollPopup=function(o){var i=e.defer(),p=n(function(){try{var e=u.popupWindow.location.origin;if(e===o&&(u.popupWindow.location.search||u.popupWindow.location.hash)){var l=u.popupWindow.location.search.substring(1).replace(/\/$/,""),c=u.popupWindow.location.hash.substring(1).replace(/[\/$]/,""),s=a.parseQueryString(c),h=a.parseQueryString(l);t.extend(h,s),h.error?i.reject(h):i.resolve(h),n.cancel(p),u.popupWindow.close()}}catch(d){}(!u.popupWindow||u.popupWindow.closed||u.popupWindow.closed===r)&&n.cancel(p)},20);return i.promise},u.prepareOptions=function(e){e=e||{};var r=e.width||500,n=e.height||500;return t.extend({width:r,height:n,left:o.screenX+(o.outerWidth-r)/2,top:o.screenY+(o.outerHeight-n)/2.5},e)},u.stringifyOptions=function(e){var r=[];return t.forEach(e,function(e,t){r.push(t+"="+e)}),r.join(",")},u}]).service("SatellizerUtils",function(){this.camelCase=function(e){return e.replace(/([\:\-\_]+(.))/g,function(e,t,r,n){return n?r.toUpperCase():r})},this.parseQueryString=function(e){var r,n,o={};return t.forEach((e||"").split("&"),function(e){e&&(n=e.split("="),r=decodeURIComponent(n[0]),o[r]=t.isDefined(n[1])?decodeURIComponent(n[1]):!0)}),o},this.joinUrl=function(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var r=[e,t].join("/"),n=function(e){return e.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return n(r)},this.merge=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(n in t&&"object"==typeof e[n]&&null!==n?r[n]=this.merge(e[n],t[n]):r[n]=e[n]);for(n in t)if(t.hasOwnProperty(n)){if(n in r)continue;r[n]=t[n]}return r}}).factory("SatellizerStorage",["$window","$log","SatellizerConfig",function(e,t,r){var n={},o=function(){try{var t=r.storageType in e&&null!==e[r.storageType];if(t){var n=Math.random().toString(36).substring(7);e[r.storageType].setItem(n,""),e[r.storageType].removeItem(n)}return t}catch(o){return!1}}();return o||t.warn(r.storageType+" is not available."),{get:function(t){return o?e[r.storageType].getItem(t):n[t]},set:function(t,i){return o?e[r.storageType].setItem(t,i):n[t]=i},remove:function(t){return o?e[r.storageType].removeItem(t):delete n[t]}}}]).factory("SatellizerInterceptor",["$q","SatellizerConfig","SatellizerStorage","SatellizerShared",function(e,t,r,n){return{request:function(e){if(e.skipAuthorization)return e;if(n.isAuthenticated()&&t.httpInterceptor(e)){var o=t.tokenPrefix?t.tokenPrefix+"_"+t.tokenName:t.tokenName,i=r.get(o);t.authHeader&&t.authToken&&(i=t.authToken+" "+i),e.headers[t.authHeader]=i}return e},responseError:function(t){return e.reject(t)}}}]).config(["$httpProvider",function(e){e.interceptors.push("SatellizerInterceptor")}])}(window,window.angular); \ No newline at end of file From 5d389c541f72071021f762f579ea05001b2a95e2 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Sat, 6 Feb 2016 22:47:57 -0500 Subject: [PATCH 11/11] Added paypal donate button --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e09f5113..bb265eea 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # [Satellizer](https://github.com/sahat/satellizer/) -[![Join the chat at https://gitter.im/sahat/satellizer](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sahat/satellizer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Donate](https://img.shields.io/badge/paypal-donate-blue.svg)](https://paypal.me/sahat) [![Join the chat at https://gitter.im/sahat/satellizer](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sahat/satellizer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](http://img.shields.io/travis/sahat/satellizer.svg?style=flat)](https://travis-ci.org/sahat/satellizer) [![Test Coverage](http://img.shields.io/codeclimate/coverage/github/sahat/satellizer.svg?style=flat)](https://codeclimate.com/github/sahat/satellizer) [![Version](https://img.shields.io/badge/version-0.13.4-brightgreen.svg)](https://www.npmjs.org/package/satellizer)