diff --git a/README.md b/README.md index e4618afa..3b8beae0 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s ``` ```html - + ``` #### NPM diff --git a/dist/satellizer.js b/dist/satellizer.js index cbeaf257..849500b4 100644 --- a/dist/satellizer.js +++ b/dist/satellizer.js @@ -1,5 +1,5 @@ /** - * Satellizer 0.15.4 + * Satellizer 0.15.5 * (c) 2016 Sahat Yalkabov * License: MIT */ @@ -510,7 +510,6 @@ this.$window = $window; this.$q = $q; this.popup = null; - this.url = 'about:blank'; // TODO remove this.defaults = { redirectUri: null }; @@ -522,8 +521,7 @@ }); return parts.join(','); }; - Popup.prototype.open = function (url, name, popupOptions) { - this.url = url; // TODO remove + Popup.prototype.open = function (url, name, popupOptions, redirectUri, dontPoll) { var width = popupOptions.width || 500; var height = popupOptions.height || 500; var options = this.stringifyOptions({ @@ -533,16 +531,22 @@ left: this.$window.screenX + ((this.$window.outerWidth - width) / 2) }); var popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name; - this.popup = window.open(this.url, popupName, options); + this.popup = this.$window.open(url, popupName, options); if (this.popup && this.popup.focus) { this.popup.focus(); } - // - // if (this.$window['cordova']) { - // return this.eventListener(this.defaults.redirectUri); // TODO pass redirect uri - // } else { - // return this.polling(redirectUri); - // } + if (dontPoll) { + return; + } + if (this.$window['cordova']) { + return this.eventListener(redirectUri); + } + else { + if (url === 'about:blank') { + this.popup.location = url; + } + return this.polling(redirectUri); + } }; Popup.prototype.polling = function (redirectUri) { var _this = this; @@ -587,7 +591,7 @@ var _this = this; return this.$q(function (resolve, reject) { _this.popup.addEventListener('loadstart', function (event) { - if (!event.url.includes(redirectUri)) { + if (event.url.indexOf(redirectUri) !== 0) { return; } var parser = document.createElement('a'); @@ -641,8 +645,11 @@ OAuth1.prototype.init = function (options, userData) { var _this = this; angular.extend(this.defaults, options); + var name = options.name, popupOptions = options.popupOptions; + var redirectUri = this.defaults.redirectUri; + // Should open an empty popup and wait until request token is received if (!this.$window['cordova']) { - this.SatellizerPopup.open('about:blank', options.name, options.popupOptions); + this.SatellizerPopup.open('about:blank', name, popupOptions, redirectUri, true); } return this.getRequestToken().then(function (response) { return _this.openPopup(options, response).then(function (popupResponse) { @@ -651,14 +658,14 @@ }); }; OAuth1.prototype.openPopup = function (options, response) { - var popupUrl = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var url = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var redirectUri = this.defaults.redirectUri; if (this.$window['cordova']) { - this.SatellizerPopup.open(popupUrl, options.name, options.popupOptions); - return this.SatellizerPopup.eventListener(this.defaults.redirectUri); + return this.SatellizerPopup.open(url, options.name, options.popupOptions, redirectUri); } else { - this.SatellizerPopup.popup.location = popupUrl; - return this.SatellizerPopup.polling(this.defaults.redirectUri); + this.SatellizerPopup.popup.location = url; + return this.SatellizerPopup.polling(redirectUri); } }; OAuth1.prototype.getRequestToken = function () { @@ -721,29 +728,25 @@ var _this = this; return this.$q(function (resolve, reject) { angular.extend(_this.defaults, options); - _this.$timeout(function () { - var stateName = _this.defaults.name + '_state'; - var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; - if (typeof state === 'function') { - _this.SatellizerStorage.set(stateName, state()); + var stateName = _this.defaults.name + '_state'; + var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; + if (typeof state === 'function') { + _this.SatellizerStorage.set(stateName, state()); + } + else if (typeof state === 'string') { + _this.SatellizerStorage.set(stateName, state); + } + var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); + _this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then(function (oauth) { + if (responseType === 'token' || !url) { + return resolve(oauth); } - else if (typeof state === 'string') { - _this.SatellizerStorage.set(stateName, state); + if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { + return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.')); } - var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); - _this.SatellizerPopup.open(url, name, popupOptions); - _this.SatellizerPopup.polling(redirectUri).then(function (oauth) { - if (responseType === 'token' || !url) { - return resolve(oauth); - } - if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { - return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + - 'authorization code request.')); - } - resolve(_this.exchangeForToken(oauth, userData)); - }) - .catch(function (error) { return reject(error); }); - }); + resolve(_this.exchangeForToken(oauth, userData)); + }).catch(function (error) { return reject(error); }); }); }; OAuth2.prototype.exchangeForToken = function (oauthData, userData) { diff --git a/dist/satellizer.js.map b/dist/satellizer.js.map index ba7c705a..e9f4f863 100644 --- a/dist/satellizer.js.map +++ b/dist/satellizer.js.map @@ -1 +1 @@ -{"version":3,"file":null,"sources":["../src/config.ts","../src/authProvider.ts","../src/utils.ts","../src/shared.ts","../src/local.ts","../src/popup.ts","../src/oauth1.ts","../src/oauth2.ts","../src/oauth.ts","../src/storage.ts","../src/interceptor.ts","../src/httpProviderConfig.ts","../src/ng1.ts"],"sourcesContent":["export default class Config {\n static get getConstant() {\n return new Config();\n }\n\n baseUrl = '/';\n loginUrl = '/auth/login';\n signupUrl = '/auth/signup';\n unlinkUrl = '/auth/unlink/';\n tokenName = 'token';\n tokenPrefix = 'satellizer';\n tokenHeader = 'Authorization';\n tokenType = 'Bearer';\n storageType = 'localStorage';\n tokenRoot = null;\n withCredentials = false;\n providers = {\n facebook: {\n name: 'facebook',\n url: '/auth/facebook',\n authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',\n redirectUri: window.location.origin + '/',\n requiredUrlParams: ['display', 'scope'],\n scope: ['email'],\n scopeDelimiter: ',',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 580, height: 400 }\n },\n google: {\n name: 'google',\n url: '/auth/google',\n authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n optionalUrlParams: ['display', 'state'],\n scope: ['profile', 'email'],\n scopePrefix: 'openid',\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 452, height: 633 },\n state: () => encodeURIComponent(Math.random().toString(36).substr(2))\n },\n github: {\n name: 'github',\n url: '/auth/github',\n authorizationEndpoint: 'https://github.com/login/oauth/authorize',\n redirectUri: window.location.origin,\n optionalUrlParams: ['scope'],\n scope: ['user:email'],\n scopeDelimiter: ' ',\n oauthType: '2.0',\n popupOptions: { width: 1020, height: 618 }\n },\n instagram: {\n name: 'instagram',\n url: '/auth/instagram',\n authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n scope: ['basic'],\n scopeDelimiter: '+',\n oauthType: '2.0'\n },\n linkedin: {\n name: 'linkedin',\n url: '/auth/linkedin',\n authorizationEndpoint: 'https://www.linkedin.com/uas/oauth2/authorization',\n redirectUri: window.location.origin,\n requiredUrlParams: ['state'],\n scope: ['r_emailaddress'],\n scopeDelimiter: ' ',\n state: 'STATE',\n oauthType: '2.0',\n popupOptions: { width: 527, height: 582 }\n },\n twitter: {\n name: 'twitter',\n url: '/auth/twitter',\n authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',\n redirectUri: window.location.origin,\n oauthType: '1.0',\n popupOptions: { width: 495, height: 645 }\n },\n twitch: {\n name: 'twitch',\n url: '/auth/twitch',\n authorizationEndpoint: 'https://api.twitch.tv/kraken/oauth2/authorize',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n scope: ['user_read'],\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 560 }\n },\n live: {\n name: 'live',\n url: '/auth/live',\n authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',\n redirectUri: window.location.origin,\n requiredUrlParams: ['display', 'scope'],\n scope: ['wl.emails'],\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 560 }\n },\n yahoo: {\n name: 'yahoo',\n url: '/auth/yahoo',\n authorizationEndpoint: 'https://api.login.yahoo.com/oauth2/request_auth',\n redirectUri: window.location.origin,\n scope: [],\n scopeDelimiter: ',',\n oauthType: '2.0',\n popupOptions: { width: 559, height: 519 }\n },\n bitbucket: {\n name: 'bitbucket',\n url: '/auth/bitbucket',\n authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',\n redirectUri: window.location.origin + '/',\n requiredUrlParams: ['scope'],\n scope: ['email'],\n scopeDelimiter: ' ',\n oauthType: '2.0',\n popupOptions: { width: 1028, height: 529 }\n },\n spotify: {\n name: 'spotify',\n url: '/auth/spotify',\n authorizationEndpoint: 'https://accounts.spotify.com/authorize',\n redirectUri: window.location.origin,\n optionalUrlParams: ['state'],\n requiredUrlParams: ['scope'],\n scope: ['user-read-email'],\n scopePrefix: '',\n scopeDelimiter: ',',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 530 },\n state: () => encodeURIComponent(Math.random().toString(36).substr(2))\n }\n };\n httpInterceptor: any = (): boolean => true;\n};\n","import Config from './config';\nimport { IOAuth1Options } from './oauth1';\nimport { IOAuth2Options } from './oauth2';\n\nexport default class AuthProvider {\n static $inject = ['SatellizerConfig'];\n\n constructor(private SatellizerConfig: Config) {}\n\n get baseUrl(): string { return this.SatellizerConfig.baseUrl; }\n set baseUrl(value) { this.SatellizerConfig.baseUrl = value; }\n\n get loginUrl(): string { return this.SatellizerConfig.loginUrl; }\n set loginUrl(value) { this.SatellizerConfig.loginUrl = value; }\n\n get signupUrl(): string { return this.SatellizerConfig.signupUrl; }\n set signupUrl(value) { this.SatellizerConfig.signupUrl = value; }\n\n get unlinkUrl(): string { return this.SatellizerConfig.unlinkUrl; }\n set unlinkUrl(value) { this.SatellizerConfig.unlinkUrl = value; }\n\n get tokenRoot(): string { return this.SatellizerConfig.tokenRoot; }\n set tokenRoot(value) { this.SatellizerConfig.tokenRoot = value; }\n\n get tokenName(): string { return this.SatellizerConfig.tokenName; }\n set tokenName(value) { this.SatellizerConfig.tokenName = value; }\n\n get tokenPrefix(): string { return this.SatellizerConfig.tokenPrefix; }\n set tokenPrefix(value) { this.SatellizerConfig.tokenPrefix = value; }\n\n get tokenHeader(): string { return this.SatellizerConfig.tokenHeader; }\n set tokenHeader(value) { this.SatellizerConfig.tokenHeader = value; }\n\n get tokenType(): string { return this.SatellizerConfig.tokenType; }\n set tokenType(value) { this.SatellizerConfig.tokenType = value; }\n\n get withCredentials(): boolean { return this.SatellizerConfig.withCredentials; }\n set withCredentials(value) { this.SatellizerConfig.withCredentials = value; }\n\n get storageType(): string { return this.SatellizerConfig.storageType; }\n set storageType(value) { this.SatellizerConfig.storageType = value; }\n\n get httpInterceptor(): boolean { return this.SatellizerConfig.httpInterceptor; }\n set httpInterceptor(value) {\n if (typeof value === 'function') {\n this.SatellizerConfig.httpInterceptor = value;\n } else {\n this.SatellizerConfig.httpInterceptor = () => value;\n }\n }\n\n facebook(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.facebook, options);\n }\n\n google(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.google, options);\n }\n\n github(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.github, options);\n }\n\n instagram(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.instagram, options);\n }\n\n linkedin(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.linkedin, options);\n }\n\n twitter(options: IOAuth1Options): void {\n angular.extend(this.SatellizerConfig.providers.twitter, options);\n }\n\n twitch(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.twitch, options);\n }\n\n live(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.live, options);\n }\n\n yahoo(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.yahoo, options);\n }\n\n bitbucket(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.bitbucket, options);\n }\n\n spotify(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.spotify, options);\n }\n\n oauth1(options: IOAuth1Options): void {\n this.SatellizerConfig.providers[options.name] = angular.extend(options, {\n oauthType: '1.0'\n });\n }\n\n oauth2(options: IOAuth2Options): void {\n this.SatellizerConfig.providers[options.name] = angular.extend(options, {\n oauthType: '2.0'\n });\n }\n\n $get(SatellizerShared, SatellizerLocal, SatellizerOAuth): any {\n return {\n login: (user, options) => SatellizerLocal.login(user, options),\n signup: (user, options) => SatellizerLocal.signup(user, options),\n logout: () => SatellizerShared.logout(),\n authenticate: (name, data) => SatellizerOAuth.authenticate(name, data),\n link: (name, data) => SatellizerOAuth.authenticate(name, data),\n unlink: (name, options) => SatellizerOAuth.unlink(name, options),\n isAuthenticated: () => SatellizerShared.isAuthenticated(),\n getPayload: () => SatellizerShared.getPayload(),\n getToken: () => SatellizerShared.getToken(),\n setToken: (token) => SatellizerShared.setToken({ access_token: token }),\n removeToken: () => SatellizerShared.removeToken(),\n setStorageType: (type) => SatellizerShared.setStorageType(type)\n };\n }\n}\n\nAuthProvider.prototype.$get.$inject = ['SatellizerShared', 'SatellizerLocal', 'SatellizerOAuth'];\n","export function joinUrl (baseUrl, url) {\n if (/^(?:[a-z]+:)?\\/\\//i.test(url)) {\n return url;\n }\n let joined = [baseUrl, url].join('/');\n let normalize = function (str) {\n return str\n .replace(/[\\/]+/g, '/')\n .replace(/\\/\\?/g, '?')\n .replace(/\\/\\#/g, '#')\n .replace(/\\:\\//g, '://');\n };\n return normalize(joined);\n}\n\nexport function getFullUrlPath (location) {\n const isHttps = location.protocol === 'https:';\n return location.protocol + '//' + location.hostname +\n ':' + (location.port || (isHttps ? '443' : '80')) +\n (/^\\//.test(location.pathname) ? location.pathname : '/' + location.pathname);\n}\n\nexport function parseQueryString (str) {\n let obj = {};\n let key;\n let value;\n angular.forEach((str || '').split('&'), (keyValue) => {\n if (keyValue) {\n value = keyValue.split('=');\n key = decodeURIComponent(value[0]);\n obj[key] = angular.isDefined(value[1]) ? decodeURIComponent(value[1]) : true;\n }\n });\n return obj;\n}\n\nexport function decodeBase64 (str) {\n let buffer;\n if (typeof module !== 'undefined' && module.exports) {\n try {\n buffer = require('buffer').Buffer;\n } catch (err) {\n // noop\n }\n }\n\n let fromCharCode = String.fromCharCode;\n\n let re_btou = new RegExp([\n '[\\xC0-\\xDF][\\x80-\\xBF]',\n '[\\xE0-\\xEF][\\x80-\\xBF]{2}',\n '[\\xF0-\\xF7][\\x80-\\xBF]{3}'\n ].join('|'), 'g');\n\n let cb_btou = function (cccc) {\n switch (cccc.length) {\n case 4:\n let cp = ((0x07 & cccc.charCodeAt(0)) << 18)\n | ((0x3f & cccc.charCodeAt(1)) << 12)\n | ((0x3f & cccc.charCodeAt(2)) << 6)\n | (0x3f & cccc.charCodeAt(3));\n let offset = cp - 0x10000;\n return (fromCharCode((offset >>> 10) + 0xD800)\n + fromCharCode((offset & 0x3FF) + 0xDC00));\n case 3:\n return fromCharCode(\n ((0x0f & cccc.charCodeAt(0)) << 12)\n | ((0x3f & cccc.charCodeAt(1)) << 6)\n | (0x3f & cccc.charCodeAt(2))\n );\n default:\n return fromCharCode(\n ((0x1f & cccc.charCodeAt(0)) << 6)\n | (0x3f & cccc.charCodeAt(1))\n );\n }\n };\n\n let btou = function (b) {\n return b.replace(re_btou, cb_btou);\n };\n\n let _decode = buffer ? function (a) {\n return (a.constructor === buffer.constructor\n ? a : new buffer(a, 'base64')).toString();\n }\n : function (a) {\n return btou(atob(a));\n };\n\n return _decode(\n String(str).replace(/[-_]/g, function (m0) {\n return m0 === '-' ? '+' : '/';\n })\n .replace(/[^A-Za-z0-9\\+\\/]/g, '')\n );\n}\n","import Config from './config';\nimport Storage from './storage';\nimport { decodeBase64 } from './utils';\n\nclass Shared {\n static $inject = ['$q', '$window', 'SatellizerConfig', 'SatellizerStorage'];\n \n private prefixedTokenName: string;\n\n constructor(private $q: angular.IQService,\n private $window: angular.IWindowService,\n private SatellizerConfig: Config,\n private SatellizerStorage: Storage) {\n const { tokenName, tokenPrefix } = this.SatellizerConfig;\n this.prefixedTokenName = tokenPrefix ? [tokenPrefix, tokenName].join('_') : tokenName;\n }\n\n getToken(): string {\n return this.SatellizerStorage.get(this.prefixedTokenName);\n }\n\n getPayload(): any {\n const token = this.SatellizerStorage.get(this.prefixedTokenName);\n\n if (token && token.split('.').length === 3) {\n try {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace('-', '+').replace('_', '/');\n return JSON.parse(decodeBase64(base64));\n } catch (e) {\n // no-op\n }\n }\n }\n\n setToken(response): void {\n const tokenRoot = this.SatellizerConfig.tokenRoot;\n const tokenName = this.SatellizerConfig.tokenName;\n const accessToken = response && response.access_token;\n\n let token;\n\n if (accessToken) {\n if (angular.isObject(accessToken) && angular.isObject(accessToken.data)) {\n response = accessToken;\n } else if (angular.isString(accessToken)) {\n token = accessToken;\n }\n }\n\n if (!token && response) {\n const tokenRootData = tokenRoot && tokenRoot.split('.').reduce((o, x) => o[x], response.data);\n token = tokenRootData ? tokenRootData[tokenName] : response.data && response.data[tokenName];\n }\n\n if (token) {\n this.SatellizerStorage.set(this.prefixedTokenName, token);\n }\n }\n\n removeToken(): void {\n this.SatellizerStorage.remove(this.prefixedTokenName);\n }\n\n isAuthenticated(): boolean {\n const token = this.SatellizerStorage.get(this.prefixedTokenName);\n\n if (token) { // Token is present\n if (token.split('.').length === 3) { // Token with a valid JWT format XXX.YYY.ZZZ\n try { // Could be a valid JWT or an access token with the same format\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace('-', '+').replace('_', '/');\n const exp = JSON.parse(this.$window.atob(base64)).exp;\n if (typeof exp === 'number') { // JWT with an optonal expiration claims\n return Math.round(new Date().getTime() / 1000) < exp;\n }\n } catch (e) {\n return true; // Pass: Non-JWT token that looks like JWT\n }\n }\n return true; // Pass: All other tokens\n }\n return false; // Fail: No token at all\n }\n\n logout(): angular.IPromise {\n this.SatellizerStorage.remove(this.prefixedTokenName);\n return this.$q.when();\n }\n\n setStorageType(type): void {\n this.SatellizerConfig.storageType = type;\n }\n}\n\nexport default Shared;\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Shared from './shared';\n\nclass Local {\n static $inject = ['$http', 'SatellizerConfig', 'SatellizerShared'];\n\n\n constructor(private $http: angular.IHttpService,\n private SatellizerConfig: Config,\n private SatellizerShared: Shared) {}\n\n login(user: string|Object, options: any = {}): angular.IHttpPromise {\n options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.loginUrl);\n options.data = user || options.data;\n options.method = options.method || 'POST';\n options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(options).then((response) => {\n this.SatellizerShared.setToken(response);\n return response;\n });\n }\n\n signup(user: string|Object, options: any = {}): angular.IHttpPromise {\n options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.signupUrl);\n options.data = user || options.data;\n options.method = options.method || 'POST';\n options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(options);\n }\n}\n\nexport default Local;\n","import { parseQueryString, getFullUrlPath } from './utils';\n\nexport interface IPopup {\n open(url: string, name: string, popupOptions: { width: number, height: number }): void;\n stringifyOptions (options: any): string;\n polling(redirectUri: string): angular.IPromise;\n eventListener(redirectUri: string): angular.IPromise;\n}\n\nexport default class Popup implements IPopup {\n static $inject = ['$interval', '$window', '$q'];\n\n public popup: any;\n private url: string;\n private defaults: { redirectUri: string };\n\n constructor(private $interval: angular.IIntervalService,\n private $window: angular.IWindowService,\n private $q: angular.IQService) {\n this.popup = null;\n this.url = 'about:blank'; // TODO remove\n this.defaults = {\n redirectUri: null\n };\n }\n\n stringifyOptions (options: any): string {\n const parts = [];\n angular.forEach(options, function (value, key) {\n parts.push(key + '=' + value);\n });\n return parts.join(',');\n }\n\n open(url: string, name: string, popupOptions: { width: number, height: number }): void {\n this.url = url; // TODO remove\n\n const width = popupOptions.width || 500;\n const height = popupOptions.height || 500;\n\n const options = this.stringifyOptions({\n width: width,\n height: height,\n top: this.$window.screenY + ((this.$window.outerHeight - height) / 2.5),\n left: this.$window.screenX + ((this.$window.outerWidth - width) / 2)\n });\n\n const popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name;\n\n this.popup = window.open(this.url, popupName, options);\n\n if (this.popup && this.popup.focus) {\n this.popup.focus();\n }\n //\n // if (this.$window['cordova']) {\n // return this.eventListener(this.defaults.redirectUri); // TODO pass redirect uri\n // } else {\n // return this.polling(redirectUri);\n // }\n }\n\n polling(redirectUri: string): angular.IPromise {\n return this.$q((resolve, reject) => {\n const redirectUriParser = document.createElement('a');\n redirectUriParser.href = redirectUri;\n const redirectUriPath = getFullUrlPath(redirectUriParser);\n\n const polling = this.$interval(() => {\n if (!this.popup || this.popup.closed || this.popup.closed === undefined) {\n this.$interval.cancel(polling);\n reject(new Error('The popup window was closed'));\n }\n\n try {\n const popupWindowPath = getFullUrlPath(this.popup.location);\n\n if (popupWindowPath === redirectUriPath) {\n if (this.popup.location.search || this.popup.location.hash) {\n const query = parseQueryString(this.popup.location.search.substring(1).replace(/\\/$/, ''));\n const hash = parseQueryString(this.popup.location.hash.substring(1).replace(/[\\/$]/, ''));\n const params = angular.extend({}, query, hash);\n\n if (params.error) {\n reject(new Error(params.error));\n } else {\n resolve(params);\n }\n } else {\n reject(new Error(\n 'OAuth redirect has occurred but no query or hash parameters were found. ' +\n 'They were either not set during the redirect, or were removed—typically by a ' +\n 'routing library—before Satellizer could read it.'\n ));\n }\n\n this.$interval.cancel(polling);\n this.popup.close();\n }\n } catch (error) {\n // Ignore DOMException: Blocked a frame with origin from accessing a cross-origin frame.\n // A hack to get around same-origin security policy errors in IE.\n }\n }, 500);\n });\n }\n\n eventListener(redirectUri): angular.IPromise {\n return this.$q((resolve, reject) => {\n this.popup.addEventListener('loadstart', (event) => {\n if (!event.url.includes(redirectUri)) {\n return;\n }\n\n const parser = document.createElement('a');\n parser.href = event.url;\n\n if (parser.search || parser.hash) {\n const query = parseQueryString(parser.search.substring(1).replace(/\\/$/, ''));\n const hash = parseQueryString(parser.hash.substring(1).replace(/[\\/$]/, ''));\n const params = angular.extend({}, query, hash);\n\n if (params.error) {\n reject(new Error(params.error));\n } else {\n resolve(params);\n }\n\n this.popup.close();\n }\n });\n\n this.popup.addEventListener('loaderror', () => {\n reject(new Error('Authorization failed'));\n });\n\n this.popup.addEventListener('exit', () => {\n reject(new Error('The popup window was closed'));\n });\n });\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport { IOAuth1Options } from './oauth1';\n\nexport interface IOAuth1 {\n init(options: any, data: any): angular.IPromise;\n getRequestToken(): angular.IHttpPromise;\n openPopup(options: IOAuth1Options, response: angular.IHttpPromiseCallbackArg): angular.IPromise;\n exchangeForToken(oauthData: any, userData: any): angular.IHttpPromise;\n buildQueryString(obj: any): string;\n}\n\nexport interface IOAuth1Options {\n name: string;\n url: string;\n authorizationEndpoint: string;\n redirectUri: string;\n scope: string[];\n scopePrefix: string;\n scopeDelimiter: string;\n requiredUrlParams: string[];\n defaultUrlParams: string[];\n oauthType: string;\n popupOptions: { width: number, height: number };\n}\n\nexport default class OAuth1 implements IOAuth1 {\n static $inject = ['$http', '$window', 'SatellizerConfig', 'SatellizerPopup'];\n\n private defaults: IOAuth1Options;\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup) {\n\n this.defaults = {\n name: null,\n url: null,\n authorizationEndpoint: null,\n scope: null,\n scopePrefix: null,\n scopeDelimiter: null,\n redirectUri: null,\n requiredUrlParams: null,\n defaultUrlParams: null,\n oauthType: '1.0',\n popupOptions: { width: null, height: null }\n };\n };\n\n init(options: IOAuth1Options, userData: any): angular.IHttpPromise {\n angular.extend(this.defaults, options);\n\n if (!this.$window['cordova']) {\n this.SatellizerPopup.open('about:blank', options.name, options.popupOptions);\n }\n\n return this.getRequestToken().then((response) => {\n return this.openPopup(options, response).then((popupResponse) => {\n return this.exchangeForToken(popupResponse, userData);\n });\n });\n }\n\n openPopup(options: IOAuth1Options, response: angular.IHttpPromiseCallbackArg): angular.IPromise {\n const popupUrl = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?');\n\n if (this.$window['cordova']) {\n this.SatellizerPopup.open(popupUrl, options.name, options.popupOptions);\n return this.SatellizerPopup.eventListener(this.defaults.redirectUri);\n } else {\n this.SatellizerPopup.popup.location = popupUrl;\n return this.SatellizerPopup.polling(this.defaults.redirectUri);\n }\n }\n\n getRequestToken(): angular.IHttpPromise {\n const url = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url;\n return this.$http.post(url, this.defaults);\n }\n\n exchangeForToken(oauthData, userData): angular.IHttpPromise {\n const payload = angular.extend({}, userData, oauthData);\n const exchangeForTokenUrl = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url;\n return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials });\n }\n\n buildQueryString(obj): string {\n const str = [];\n angular.forEach(obj, function (value, key) {\n str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));\n });\n return str.join('&');\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport Storage from './storage';\n\nexport interface IOAuth2Options {\n name: string;\n url: string;\n clientId: string;\n authorizationEndpoint: string;\n redirectUri: string;\n scope: string[];\n scopePrefix: string;\n scopeDelimiter: string;\n state?: string|(() => string);\n requiredUrlParams: string[];\n defaultUrlParams: string[];\n responseType: string;\n responseParams: {\n code: string,\n clientId: string,\n redirectUri: string\n };\n oauthType: string;\n popupOptions: { width: number, height: number };\n}\n\nexport default class OAuth2 {\n static $inject = ['$http', '$window', '$timeout', '$q', 'SatellizerConfig', 'SatellizerPopup', 'SatellizerStorage'];\n\n static camelCase(name): string {\n return name.replace(/([\\:\\-\\_]+(.))/g, (_, separator, letter, offset) => {\n return offset ? letter.toUpperCase() : letter;\n });\n }\n\n public defaults: IOAuth2Options;\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private $timeout: angular.ITimeoutService,\n private $q: angular.IQService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup,\n private SatellizerStorage: Storage) {\n\n this.defaults = {\n name: null,\n url: null,\n clientId: null,\n authorizationEndpoint: null,\n redirectUri: null,\n scope: null,\n scopePrefix: null,\n scopeDelimiter: null,\n state: null,\n requiredUrlParams: null,\n defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],\n responseType: 'code',\n responseParams: {\n code: 'code',\n clientId: 'clientId',\n redirectUri: 'redirectUri'\n },\n oauthType: '2.0',\n popupOptions: { width: null, height: null }\n };\n }\n\n init(options: IOAuth2Options, userData: any): angular.IPromise {\n return this.$q((resolve, reject) => {\n angular.extend(this.defaults, options);\n this.$timeout(() => {\n const stateName = this.defaults.name + '_state';\n const { name, state, popupOptions, redirectUri, responseType } = this.defaults;\n\n if (typeof state === 'function') {\n this.SatellizerStorage.set(stateName, state());\n } else if (typeof state === 'string') {\n this.SatellizerStorage.set(stateName, state);\n }\n \n const url = [this.defaults.authorizationEndpoint, this.buildQueryString()].join('?');\n\n this.SatellizerPopup.open(url, name, popupOptions);\n\n this.SatellizerPopup.polling(redirectUri).then((oauth: any): void|angular.IPromise|angular.IHttpPromise => {\n\n if (responseType === 'token' || !url) {\n return resolve(oauth);\n }\n\n if (oauth.state && oauth.state !== this.SatellizerStorage.get(stateName)) {\n return reject(new Error(\n 'The value returned in the state parameter does not match the state value from your original ' +\n 'authorization code request.'\n ));\n }\n\n resolve(this.exchangeForToken(oauth, userData));\n })\n .catch(error => reject(error));\n });\n });\n }\n\n exchangeForToken(oauthData: { code?, state? }, userData: any): angular.IHttpPromise {\n const payload = angular.extend({}, userData);\n\n angular.forEach(this.defaults.responseParams, (value, key) => {\n switch (key) {\n case 'code':\n payload[value] = oauthData.code;\n break;\n case 'clientId':\n payload[value] = this.defaults.clientId;\n break;\n case 'redirectUri':\n payload[value] = this.defaults.redirectUri;\n break;\n default:\n payload[value] = oauthData[key];\n }\n });\n\n if (oauthData.state) {\n payload.state = oauthData.state;\n }\n\n let exchangeForTokenUrl = this.SatellizerConfig.baseUrl ?\n joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) :\n this.defaults.url;\n\n return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials });\n }\n\n buildQueryString(): string {\n const keyValuePairs = [];\n const urlParamsCategories = ['defaultUrlParams', 'requiredUrlParams', 'optionalUrlParams'];\n\n angular.forEach(urlParamsCategories, (paramsCategory) => {\n angular.forEach(this.defaults[paramsCategory], (paramName) => {\n const camelizedName = OAuth2.camelCase(paramName);\n let paramValue = angular.isFunction(this.defaults[paramName]) ? this.defaults[paramName]() : this.defaults[camelizedName];\n\n if (paramName === 'redirect_uri' && !paramValue) {\n return;\n }\n if (paramName === 'state') {\n const stateName = this.defaults.name + '_state';\n paramValue = encodeURIComponent(this.SatellizerStorage.get(stateName));\n }\n if (paramName === 'scope' && Array.isArray(paramValue)) {\n paramValue = paramValue.join(this.defaults.scopeDelimiter);\n if (this.defaults.scopePrefix) {\n paramValue = [this.defaults.scopePrefix, paramValue].join(this.defaults.scopeDelimiter);\n }\n }\n\n keyValuePairs.push([paramName, paramValue]);\n });\n });\n\n return keyValuePairs.map(pair => pair.join('=')).join('&');\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport Storage from './storage';\nimport Shared from './shared';\nimport OAuth1 from './oauth1';\nimport OAuth2 from './oauth2';\n\nexport default class OAuth {\n static $inject = [\n '$http',\n '$window',\n '$timeout',\n '$q',\n 'SatellizerConfig',\n 'SatellizerPopup',\n 'SatellizerStorage',\n 'SatellizerShared',\n 'SatellizerOAuth1',\n 'SatellizerOAuth2'\n ];\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private $timeout: angular.ITimeoutService,\n private $q: angular.IQService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup,\n private SatellizerStorage: Storage,\n private SatellizerShared: Shared,\n private SatellizerOAuth1: OAuth1,\n private SatellizerOAuth2: OAuth2) {}\n\n authenticate(name: string, userData?: any): angular.IPromise {\n return this.$q((resolve, reject) => {\n const provider = this.SatellizerConfig.providers[name];\n\n let oauth = null;\n\n switch (provider.oauthType) {\n case '1.0':\n oauth = new OAuth1(this.$http, this.$window, this.SatellizerConfig, this.SatellizerPopup);\n break;\n case '2.0':\n oauth = new OAuth2(this.$http, this.$window, this.$timeout, this.$q, this.SatellizerConfig, this.SatellizerPopup, this.SatellizerStorage);\n break;\n default:\n return reject(new Error('Invalid OAuth Type'));\n }\n\n return oauth.init(provider, userData).then((response) => {\n if (provider.url) {\n this.SatellizerShared.setToken(response);\n }\n resolve(response);\n }).catch((error) => {\n reject(error);\n });\n });\n }\n\n unlink(provider: string, httpOptions: any = {}): angular.IHttpPromise {\n httpOptions.url = httpOptions.url ? httpOptions.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.unlinkUrl);\n httpOptions.data = { provider: provider } || httpOptions.data;\n httpOptions.method = httpOptions.method || 'POST';\n httpOptions.withCredentials = httpOptions.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(httpOptions);\n }\n}\n","import Config from './config';\n\nexport default class Storage {\n static $inject = ['$window', 'SatellizerConfig'];\n\n private memoryStore: any;\n private storageType: string;\n\n constructor(private $window: angular.IHttpService,\n private SatellizerConfig: Config) {\n this.memoryStore = {};\n }\n\n get(key: string): string {\n try {\n return this.$window[this.SatellizerConfig.storageType].getItem(key);\n } catch (e) {\n return this.memoryStore[key];\n }\n }\n\n set(key: string, value: string): void {\n try {\n this.$window[this.SatellizerConfig.storageType].setItem(key, value);\n } catch (e) {\n this.memoryStore[key] = value;\n }\n }\n\n remove(key: string): void {\n try {\n this.$window[this.SatellizerConfig.storageType].removeItem(key);\n } catch (e) {\n delete this.memoryStore[key];\n }\n }\n}\n","import Config from './config';\nimport Shared from './shared';\nimport Storage from './storage';\n\nexport default class Interceptor implements angular.IHttpInterceptor {\n\n static $inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage'];\n\n static Factory(SatellizerConfig: Config, SatellizerShared: Shared, SatellizerStorage: Storage): Interceptor {\n return new Interceptor(SatellizerConfig, SatellizerShared, SatellizerStorage);\n }\n\n constructor(private SatellizerConfig: Config,\n private SatellizerShared: Shared,\n private SatellizerStorage: Storage) {\n }\n\n request = (config: angular.IRequestConfig): angular.IRequestConfig => {\n if (config['skipAuthorization']) {\n return config;\n }\n\n if (this.SatellizerShared.isAuthenticated() && this.SatellizerConfig.httpInterceptor()) {\n const tokenName = this.SatellizerConfig.tokenPrefix ?\n [this.SatellizerConfig.tokenPrefix, this.SatellizerConfig.tokenName].join('_') : this.SatellizerConfig.tokenName;\n let token = this.SatellizerStorage.get(tokenName);\n\n if (this.SatellizerConfig.tokenHeader && this.SatellizerConfig.tokenType) {\n token = this.SatellizerConfig.tokenType + ' ' + token;\n }\n\n config.headers[this.SatellizerConfig.tokenHeader] = token;\n }\n\n return config;\n };\n}\n\nInterceptor.Factory.$inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage'];","import Interceptor from './interceptor';\n\nexport default class HttpProviderConfig {\n static $inject = ['$httpProvider'];\n\n constructor(private $httpProvider: angular.IHttpProvider) {\n $httpProvider.interceptors.push(Interceptor.Factory);\n }\n}\n","import Config from './config';\nimport AuthProvider from './authProvider';\nimport Shared from './shared';\nimport Local from './local';\nimport Popup from './popup';\nimport OAuth from './oauth';\nimport OAuth2 from './oauth2';\nimport OAuth1 from './oauth1';\nimport Storage from './storage';\nimport Interceptor from './interceptor';\nimport HttpProviderConfig from './httpProviderConfig';\n\nangular.module('satellizer', [])\n .provider('$auth', ['SatellizerConfig', (SatellizerConfig) => new AuthProvider(SatellizerConfig)])\n .constant('SatellizerConfig', Config.getConstant)\n .service('SatellizerShared', Shared)\n .service('SatellizerLocal', Local)\n .service('SatellizerPopup', Popup)\n .service('SatellizerOAuth', OAuth)\n .service('SatellizerOAuth2', OAuth2)\n .service('SatellizerOAuth1', OAuth1)\n .service('SatellizerStorage', Storage)\n .service('SatellizerInterceptor', Interceptor)\n .config(['$httpProvider', ($httpProvider) => new HttpProviderConfig($httpProvider)]);\n\nexport default 'satellizer';\n\n"],"names":[],"mappings":";;;;;;;;;;;;IAAe;QAAA;YAKb,YAAO,GAAG,GAAG,CAAC;YACd,aAAQ,GAAG,aAAa,CAAC;YACzB,cAAS,GAAG,cAAc,CAAC;YAC3B,cAAS,GAAG,eAAe,CAAC;YAC5B,cAAS,GAAG,OAAO,CAAC;YACpB,gBAAW,GAAG,YAAY,CAAC;YAC3B,gBAAW,GAAG,eAAe,CAAC;YAC9B,cAAS,GAAG,QAAQ,CAAC;YACrB,gBAAW,GAAG,cAAc,CAAC;YAC7B,cAAS,GAAG,IAAI,CAAC;YACjB,oBAAe,GAAG,KAAK,CAAC;YACxB,cAAS,GAAG;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,UAAU;oBAChB,GAAG,EAAE,gBAAgB;oBACrB,qBAAqB,EAAE,4CAA4C;oBACnE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG;oBACzC,iBAAiB,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;oBACvC,KAAK,EAAE,CAAC,OAAO,CAAC;oBAChB,cAAc,EAAE,GAAG;oBACnB,OAAO,EAAE,OAAO;oBAChB,SAAS,EAAE,KAAK;oBAChB,YAAY,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;iBAC1C;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,GAAG,EAAE,cAAc;o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AAY,CAAC,gBAAgB,CAAC,GAAA,CAAC,CAAC;SACjG,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC,WAAW,CAAC;SAChD,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC;SACrC,OAAO,CAAC,uBAAuB,EAAE,WAAW,CAAC;SAC7C,MAAM,CAAC,CAAC,eAAe,EAAE,UAAC,aAAa,IAAK,OAAA,IAAI,kBAAkB,CAAC,aAAa,CAAC,GAAA,CAAC,CAAC,CAAC;AAEvF,cAAe,YAAY,CAAC;;;;"} \ No newline at end of file +{"version":3,"file":null,"sources":["../src/config.ts","../src/authProvider.ts","../src/utils.ts","../src/shared.ts","../src/local.ts","../src/popup.ts","../src/oauth1.ts","../src/oauth2.ts","../src/oauth.ts","../src/storage.ts","../src/interceptor.ts","../src/httpProviderConfig.ts","../src/ng1.ts"],"sourcesContent":["export default class Config {\n static get getConstant() {\n return new Config();\n }\n\n baseUrl = '/';\n loginUrl = '/auth/login';\n signupUrl = '/auth/signup';\n unlinkUrl = '/auth/unlink/';\n tokenName = 'token';\n tokenPrefix = 'satellizer';\n tokenHeader = 'Authorization';\n tokenType = 'Bearer';\n storageType = 'localStorage';\n tokenRoot = null;\n withCredentials = false;\n providers = {\n facebook: {\n name: 'facebook',\n url: '/auth/facebook',\n authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',\n redirectUri: window.location.origin + '/',\n requiredUrlParams: ['display', 'scope'],\n scope: ['email'],\n scopeDelimiter: ',',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 580, height: 400 }\n },\n google: {\n name: 'google',\n url: '/auth/google',\n authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n optionalUrlParams: ['display', 'state'],\n scope: ['profile', 'email'],\n scopePrefix: 'openid',\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 452, height: 633 },\n state: () => encodeURIComponent(Math.random().toString(36).substr(2))\n },\n github: {\n name: 'github',\n url: '/auth/github',\n authorizationEndpoint: 'https://github.com/login/oauth/authorize',\n redirectUri: window.location.origin,\n optionalUrlParams: ['scope'],\n scope: ['user:email'],\n scopeDelimiter: ' ',\n oauthType: '2.0',\n popupOptions: { width: 1020, height: 618 }\n },\n instagram: {\n name: 'instagram',\n url: '/auth/instagram',\n authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n scope: ['basic'],\n scopeDelimiter: '+',\n oauthType: '2.0'\n },\n linkedin: {\n name: 'linkedin',\n url: '/auth/linkedin',\n authorizationEndpoint: 'https://www.linkedin.com/uas/oauth2/authorization',\n redirectUri: window.location.origin,\n requiredUrlParams: ['state'],\n scope: ['r_emailaddress'],\n scopeDelimiter: ' ',\n state: 'STATE',\n oauthType: '2.0',\n popupOptions: { width: 527, height: 582 }\n },\n twitter: {\n name: 'twitter',\n url: '/auth/twitter',\n authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',\n redirectUri: window.location.origin,\n oauthType: '1.0',\n popupOptions: { width: 495, height: 645 }\n },\n twitch: {\n name: 'twitch',\n url: '/auth/twitch',\n authorizationEndpoint: 'https://api.twitch.tv/kraken/oauth2/authorize',\n redirectUri: window.location.origin,\n requiredUrlParams: ['scope'],\n scope: ['user_read'],\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 560 }\n },\n live: {\n name: 'live',\n url: '/auth/live',\n authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',\n redirectUri: window.location.origin,\n requiredUrlParams: ['display', 'scope'],\n scope: ['wl.emails'],\n scopeDelimiter: ' ',\n display: 'popup',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 560 }\n },\n yahoo: {\n name: 'yahoo',\n url: '/auth/yahoo',\n authorizationEndpoint: 'https://api.login.yahoo.com/oauth2/request_auth',\n redirectUri: window.location.origin,\n scope: [],\n scopeDelimiter: ',',\n oauthType: '2.0',\n popupOptions: { width: 559, height: 519 }\n },\n bitbucket: {\n name: 'bitbucket',\n url: '/auth/bitbucket',\n authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',\n redirectUri: window.location.origin + '/',\n requiredUrlParams: ['scope'],\n scope: ['email'],\n scopeDelimiter: ' ',\n oauthType: '2.0',\n popupOptions: { width: 1028, height: 529 }\n },\n spotify: {\n name: 'spotify',\n url: '/auth/spotify',\n authorizationEndpoint: 'https://accounts.spotify.com/authorize',\n redirectUri: window.location.origin,\n optionalUrlParams: ['state'],\n requiredUrlParams: ['scope'],\n scope: ['user-read-email'],\n scopePrefix: '',\n scopeDelimiter: ',',\n oauthType: '2.0',\n popupOptions: { width: 500, height: 530 },\n state: () => encodeURIComponent(Math.random().toString(36).substr(2))\n }\n };\n httpInterceptor: any = (): boolean => true;\n};\n","import Config from './config';\nimport { IOAuth1Options } from './oauth1';\nimport { IOAuth2Options } from './oauth2';\n\nexport default class AuthProvider {\n static $inject = ['SatellizerConfig'];\n\n constructor(private SatellizerConfig: Config) {}\n\n get baseUrl(): string { return this.SatellizerConfig.baseUrl; }\n set baseUrl(value) { this.SatellizerConfig.baseUrl = value; }\n\n get loginUrl(): string { return this.SatellizerConfig.loginUrl; }\n set loginUrl(value) { this.SatellizerConfig.loginUrl = value; }\n\n get signupUrl(): string { return this.SatellizerConfig.signupUrl; }\n set signupUrl(value) { this.SatellizerConfig.signupUrl = value; }\n\n get unlinkUrl(): string { return this.SatellizerConfig.unlinkUrl; }\n set unlinkUrl(value) { this.SatellizerConfig.unlinkUrl = value; }\n\n get tokenRoot(): string { return this.SatellizerConfig.tokenRoot; }\n set tokenRoot(value) { this.SatellizerConfig.tokenRoot = value; }\n\n get tokenName(): string { return this.SatellizerConfig.tokenName; }\n set tokenName(value) { this.SatellizerConfig.tokenName = value; }\n\n get tokenPrefix(): string { return this.SatellizerConfig.tokenPrefix; }\n set tokenPrefix(value) { this.SatellizerConfig.tokenPrefix = value; }\n\n get tokenHeader(): string { return this.SatellizerConfig.tokenHeader; }\n set tokenHeader(value) { this.SatellizerConfig.tokenHeader = value; }\n\n get tokenType(): string { return this.SatellizerConfig.tokenType; }\n set tokenType(value) { this.SatellizerConfig.tokenType = value; }\n\n get withCredentials(): boolean { return this.SatellizerConfig.withCredentials; }\n set withCredentials(value) { this.SatellizerConfig.withCredentials = value; }\n\n get storageType(): string { return this.SatellizerConfig.storageType; }\n set storageType(value) { this.SatellizerConfig.storageType = value; }\n\n get httpInterceptor(): boolean { return this.SatellizerConfig.httpInterceptor; }\n set httpInterceptor(value) {\n if (typeof value === 'function') {\n this.SatellizerConfig.httpInterceptor = value;\n } else {\n this.SatellizerConfig.httpInterceptor = () => value;\n }\n }\n\n facebook(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.facebook, options);\n }\n\n google(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.google, options);\n }\n\n github(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.github, options);\n }\n\n instagram(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.instagram, options);\n }\n\n linkedin(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.linkedin, options);\n }\n\n twitter(options: IOAuth1Options): void {\n angular.extend(this.SatellizerConfig.providers.twitter, options);\n }\n\n twitch(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.twitch, options);\n }\n\n live(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.live, options);\n }\n\n yahoo(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.yahoo, options);\n }\n\n bitbucket(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.bitbucket, options);\n }\n\n spotify(options: IOAuth2Options): void {\n angular.extend(this.SatellizerConfig.providers.spotify, options);\n }\n\n oauth1(options: IOAuth1Options): void {\n this.SatellizerConfig.providers[options.name] = angular.extend(options, {\n oauthType: '1.0'\n });\n }\n\n oauth2(options: IOAuth2Options): void {\n this.SatellizerConfig.providers[options.name] = angular.extend(options, {\n oauthType: '2.0'\n });\n }\n\n $get(SatellizerShared, SatellizerLocal, SatellizerOAuth): any {\n return {\n login: (user, options) => SatellizerLocal.login(user, options),\n signup: (user, options) => SatellizerLocal.signup(user, options),\n logout: () => SatellizerShared.logout(),\n authenticate: (name, data) => SatellizerOAuth.authenticate(name, data),\n link: (name, data) => SatellizerOAuth.authenticate(name, data),\n unlink: (name, options) => SatellizerOAuth.unlink(name, options),\n isAuthenticated: () => SatellizerShared.isAuthenticated(),\n getPayload: () => SatellizerShared.getPayload(),\n getToken: () => SatellizerShared.getToken(),\n setToken: (token) => SatellizerShared.setToken({ access_token: token }),\n removeToken: () => SatellizerShared.removeToken(),\n setStorageType: (type) => SatellizerShared.setStorageType(type)\n };\n }\n}\n\nAuthProvider.prototype.$get.$inject = ['SatellizerShared', 'SatellizerLocal', 'SatellizerOAuth'];\n","export function joinUrl (baseUrl, url) {\n if (/^(?:[a-z]+:)?\\/\\//i.test(url)) {\n return url;\n }\n let joined = [baseUrl, url].join('/');\n let normalize = function (str) {\n return str\n .replace(/[\\/]+/g, '/')\n .replace(/\\/\\?/g, '?')\n .replace(/\\/\\#/g, '#')\n .replace(/\\:\\//g, '://');\n };\n return normalize(joined);\n}\n\nexport function getFullUrlPath (location) {\n const isHttps = location.protocol === 'https:';\n return location.protocol + '//' + location.hostname +\n ':' + (location.port || (isHttps ? '443' : '80')) +\n (/^\\//.test(location.pathname) ? location.pathname : '/' + location.pathname);\n}\n\nexport function parseQueryString (str) {\n let obj = {};\n let key;\n let value;\n angular.forEach((str || '').split('&'), (keyValue) => {\n if (keyValue) {\n value = keyValue.split('=');\n key = decodeURIComponent(value[0]);\n obj[key] = angular.isDefined(value[1]) ? decodeURIComponent(value[1]) : true;\n }\n });\n return obj;\n}\n\nexport function decodeBase64 (str) {\n let buffer;\n if (typeof module !== 'undefined' && module.exports) {\n try {\n buffer = require('buffer').Buffer;\n } catch (err) {\n // noop\n }\n }\n\n let fromCharCode = String.fromCharCode;\n\n let re_btou = new RegExp([\n '[\\xC0-\\xDF][\\x80-\\xBF]',\n '[\\xE0-\\xEF][\\x80-\\xBF]{2}',\n '[\\xF0-\\xF7][\\x80-\\xBF]{3}'\n ].join('|'), 'g');\n\n let cb_btou = function (cccc) {\n switch (cccc.length) {\n case 4:\n let cp = ((0x07 & cccc.charCodeAt(0)) << 18)\n | ((0x3f & cccc.charCodeAt(1)) << 12)\n | ((0x3f & cccc.charCodeAt(2)) << 6)\n | (0x3f & cccc.charCodeAt(3));\n let offset = cp - 0x10000;\n return (fromCharCode((offset >>> 10) + 0xD800)\n + fromCharCode((offset & 0x3FF) + 0xDC00));\n case 3:\n return fromCharCode(\n ((0x0f & cccc.charCodeAt(0)) << 12)\n | ((0x3f & cccc.charCodeAt(1)) << 6)\n | (0x3f & cccc.charCodeAt(2))\n );\n default:\n return fromCharCode(\n ((0x1f & cccc.charCodeAt(0)) << 6)\n | (0x3f & cccc.charCodeAt(1))\n );\n }\n };\n\n let btou = function (b) {\n return b.replace(re_btou, cb_btou);\n };\n\n let _decode = buffer ? function (a) {\n return (a.constructor === buffer.constructor\n ? a : new buffer(a, 'base64')).toString();\n }\n : function (a) {\n return btou(atob(a));\n };\n\n return _decode(\n String(str).replace(/[-_]/g, function (m0) {\n return m0 === '-' ? '+' : '/';\n })\n .replace(/[^A-Za-z0-9\\+\\/]/g, '')\n );\n}\n","import Config from './config';\nimport Storage from './storage';\nimport { decodeBase64 } from './utils';\n\nclass Shared {\n static $inject = ['$q', '$window', 'SatellizerConfig', 'SatellizerStorage'];\n \n private prefixedTokenName: string;\n\n constructor(private $q: angular.IQService,\n private $window: angular.IWindowService,\n private SatellizerConfig: Config,\n private SatellizerStorage: Storage) {\n const { tokenName, tokenPrefix } = this.SatellizerConfig;\n this.prefixedTokenName = tokenPrefix ? [tokenPrefix, tokenName].join('_') : tokenName;\n }\n\n getToken(): string {\n return this.SatellizerStorage.get(this.prefixedTokenName);\n }\n\n getPayload(): any {\n const token = this.SatellizerStorage.get(this.prefixedTokenName);\n\n if (token && token.split('.').length === 3) {\n try {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace('-', '+').replace('_', '/');\n return JSON.parse(decodeBase64(base64));\n } catch (e) {\n // no-op\n }\n }\n }\n\n setToken(response): void {\n const tokenRoot = this.SatellizerConfig.tokenRoot;\n const tokenName = this.SatellizerConfig.tokenName;\n const accessToken = response && response.access_token;\n\n let token;\n\n if (accessToken) {\n if (angular.isObject(accessToken) && angular.isObject(accessToken.data)) {\n response = accessToken;\n } else if (angular.isString(accessToken)) {\n token = accessToken;\n }\n }\n\n if (!token && response) {\n const tokenRootData = tokenRoot && tokenRoot.split('.').reduce((o, x) => o[x], response.data);\n token = tokenRootData ? tokenRootData[tokenName] : response.data && response.data[tokenName];\n }\n\n if (token) {\n this.SatellizerStorage.set(this.prefixedTokenName, token);\n }\n }\n\n removeToken(): void {\n this.SatellizerStorage.remove(this.prefixedTokenName);\n }\n\n isAuthenticated(): boolean {\n const token = this.SatellizerStorage.get(this.prefixedTokenName);\n\n if (token) { // Token is present\n if (token.split('.').length === 3) { // Token with a valid JWT format XXX.YYY.ZZZ\n try { // Could be a valid JWT or an access token with the same format\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace('-', '+').replace('_', '/');\n const exp = JSON.parse(this.$window.atob(base64)).exp;\n if (typeof exp === 'number') { // JWT with an optonal expiration claims\n return Math.round(new Date().getTime() / 1000) < exp;\n }\n } catch (e) {\n return true; // Pass: Non-JWT token that looks like JWT\n }\n }\n return true; // Pass: All other tokens\n }\n return false; // Fail: No token at all\n }\n\n logout(): angular.IPromise {\n this.SatellizerStorage.remove(this.prefixedTokenName);\n return this.$q.when();\n }\n\n setStorageType(type): void {\n this.SatellizerConfig.storageType = type;\n }\n}\n\nexport default Shared;\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Shared from './shared';\n\nclass Local {\n static $inject = ['$http', 'SatellizerConfig', 'SatellizerShared'];\n\n\n constructor(private $http: angular.IHttpService,\n private SatellizerConfig: Config,\n private SatellizerShared: Shared) {}\n\n login(user: string|Object, options: any = {}): angular.IHttpPromise {\n options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.loginUrl);\n options.data = user || options.data;\n options.method = options.method || 'POST';\n options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(options).then((response) => {\n this.SatellizerShared.setToken(response);\n return response;\n });\n }\n\n signup(user: string|Object, options: any = {}): angular.IHttpPromise {\n options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.signupUrl);\n options.data = user || options.data;\n options.method = options.method || 'POST';\n options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(options);\n }\n}\n\nexport default Local;\n","import { parseQueryString, getFullUrlPath } from './utils';\n\nexport interface IPopup {\n open(url: string, name: string, popupOptions: { width: number, height: number }, redirectUri: string): void;\n stringifyOptions (options: any): string;\n polling(redirectUri: string): angular.IPromise;\n eventListener(redirectUri: string): angular.IPromise;\n}\n\nexport default class Popup implements IPopup {\n static $inject = ['$interval', '$window', '$q'];\n\n public popup: any;\n private url: string;\n private defaults: { redirectUri: string };\n\n constructor(private $interval: angular.IIntervalService,\n private $window: angular.IWindowService,\n private $q: angular.IQService) {\n this.popup = null;\n this.defaults = {\n redirectUri: null\n };\n }\n\n stringifyOptions (options: any): string {\n const parts = [];\n angular.forEach(options, function (value, key) {\n parts.push(key + '=' + value);\n });\n return parts.join(',');\n }\n\n open(url: string,\n name: string,\n popupOptions: { width: number, height: number },\n redirectUri: string,\n dontPoll?: boolean): angular.IPromise {\n const width = popupOptions.width || 500;\n const height = popupOptions.height || 500;\n\n const options = this.stringifyOptions({\n width: width,\n height: height,\n top: this.$window.screenY + ((this.$window.outerHeight - height) / 2.5),\n left: this.$window.screenX + ((this.$window.outerWidth - width) / 2)\n });\n\n const popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name;\n\n this.popup = this.$window.open(url, popupName, options);\n\n if (this.popup && this.popup.focus) {\n this.popup.focus();\n }\n\n if (dontPoll) {\n return;\n }\n\n if (this.$window['cordova']) {\n return this.eventListener(redirectUri);\n } else {\n if (url === 'about:blank') {\n this.popup.location = url;\n }\n return this.polling(redirectUri);\n }\n\n }\n\n polling(redirectUri: string): angular.IPromise {\n return this.$q((resolve, reject) => {\n const redirectUriParser = document.createElement('a');\n redirectUriParser.href = redirectUri;\n const redirectUriPath = getFullUrlPath(redirectUriParser);\n\n const polling = this.$interval(() => {\n if (!this.popup || this.popup.closed || this.popup.closed === undefined) {\n this.$interval.cancel(polling);\n reject(new Error('The popup window was closed'));\n }\n\n try {\n const popupWindowPath = getFullUrlPath(this.popup.location);\n\n if (popupWindowPath === redirectUriPath) {\n if (this.popup.location.search || this.popup.location.hash) {\n const query = parseQueryString(this.popup.location.search.substring(1).replace(/\\/$/, ''));\n const hash = parseQueryString(this.popup.location.hash.substring(1).replace(/[\\/$]/, ''));\n const params = angular.extend({}, query, hash);\n\n if (params.error) {\n reject(new Error(params.error));\n } else {\n resolve(params);\n }\n } else {\n reject(new Error(\n 'OAuth redirect has occurred but no query or hash parameters were found. ' +\n 'They were either not set during the redirect, or were removed—typically by a ' +\n 'routing library—before Satellizer could read it.'\n ));\n }\n\n this.$interval.cancel(polling);\n this.popup.close();\n }\n } catch (error) {\n // Ignore DOMException: Blocked a frame with origin from accessing a cross-origin frame.\n // A hack to get around same-origin security policy errors in IE.\n }\n }, 500);\n });\n }\n\n eventListener(redirectUri): angular.IPromise {\n return this.$q((resolve, reject) => {\n this.popup.addEventListener('loadstart', (event) => {\n if (event.url.indexOf(redirectUri) !== 0) {\n return;\n }\n\n const parser = document.createElement('a');\n parser.href = event.url;\n\n if (parser.search || parser.hash) {\n const query = parseQueryString(parser.search.substring(1).replace(/\\/$/, ''));\n const hash = parseQueryString(parser.hash.substring(1).replace(/[\\/$]/, ''));\n const params = angular.extend({}, query, hash);\n\n if (params.error) {\n reject(new Error(params.error));\n } else {\n resolve(params);\n }\n\n this.popup.close();\n }\n });\n\n this.popup.addEventListener('loaderror', () => {\n reject(new Error('Authorization failed'));\n });\n\n this.popup.addEventListener('exit', () => {\n reject(new Error('The popup window was closed'));\n });\n });\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport { IOAuth1Options } from './oauth1';\n\nexport interface IOAuth1 {\n init(options: any, data: any): angular.IPromise;\n getRequestToken(): angular.IHttpPromise;\n openPopup(options: IOAuth1Options, response: angular.IHttpPromiseCallbackArg): angular.IPromise;\n exchangeForToken(oauthData: any, userData: any): angular.IHttpPromise;\n buildQueryString(obj: any): string;\n}\n\nexport interface IOAuth1Options {\n name: string;\n url: string;\n authorizationEndpoint: string;\n redirectUri: string;\n scope: string[];\n scopePrefix: string;\n scopeDelimiter: string;\n requiredUrlParams: string[];\n defaultUrlParams: string[];\n oauthType: string;\n popupOptions: { width: number, height: number };\n}\n\nexport default class OAuth1 implements IOAuth1 {\n static $inject = ['$http', '$window', 'SatellizerConfig', 'SatellizerPopup'];\n\n private defaults: IOAuth1Options;\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup) {\n\n this.defaults = {\n name: null,\n url: null,\n authorizationEndpoint: null,\n scope: null,\n scopePrefix: null,\n scopeDelimiter: null,\n redirectUri: null,\n requiredUrlParams: null,\n defaultUrlParams: null,\n oauthType: '1.0',\n popupOptions: { width: null, height: null }\n };\n };\n\n init(options: IOAuth1Options, userData: any): angular.IHttpPromise {\n angular.extend(this.defaults, options);\n const { name, popupOptions } = options;\n const { redirectUri } = this.defaults;\n\n // Should open an empty popup and wait until request token is received\n if (!this.$window['cordova']) {\n this.SatellizerPopup.open('about:blank', name, popupOptions, redirectUri, true);\n }\n\n return this.getRequestToken().then((response) => {\n return this.openPopup(options, response).then((popupResponse) => {\n return this.exchangeForToken(popupResponse, userData);\n });\n });\n }\n\n openPopup(options: IOAuth1Options, response: angular.IHttpPromiseCallbackArg): angular.IPromise {\n const url = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?');\n const { redirectUri } = this.defaults;\n\n if (this.$window['cordova']) {\n return this.SatellizerPopup.open(url, options.name, options.popupOptions, redirectUri);\n } else {\n this.SatellizerPopup.popup.location = url;\n return this.SatellizerPopup.polling(redirectUri);\n }\n }\n\n getRequestToken(): angular.IHttpPromise {\n const url = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url;\n return this.$http.post(url, this.defaults);\n }\n\n exchangeForToken(oauthData, userData): angular.IHttpPromise {\n const payload = angular.extend({}, userData, oauthData);\n const exchangeForTokenUrl = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url;\n return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials });\n }\n\n buildQueryString(obj): string {\n const str = [];\n angular.forEach(obj, function (value, key) {\n str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));\n });\n return str.join('&');\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport Storage from './storage';\n\nexport interface IOAuth2Options {\n name: string;\n url: string;\n clientId: string;\n authorizationEndpoint: string;\n redirectUri: string;\n scope: string[];\n scopePrefix: string;\n scopeDelimiter: string;\n state?: string|(() => string);\n requiredUrlParams: string[];\n defaultUrlParams: string[];\n responseType: string;\n responseParams: {\n code: string,\n clientId: string,\n redirectUri: string\n };\n oauthType: string;\n popupOptions: { width: number, height: number };\n}\n\nexport default class OAuth2 {\n static $inject = ['$http', '$window', '$timeout', '$q', 'SatellizerConfig', 'SatellizerPopup', 'SatellizerStorage'];\n\n static camelCase(name): string {\n return name.replace(/([\\:\\-\\_]+(.))/g, (_, separator, letter, offset) => {\n return offset ? letter.toUpperCase() : letter;\n });\n }\n\n public defaults: IOAuth2Options;\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private $timeout: angular.ITimeoutService,\n private $q: angular.IQService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup,\n private SatellizerStorage: Storage) {\n\n this.defaults = {\n name: null,\n url: null,\n clientId: null,\n authorizationEndpoint: null,\n redirectUri: null,\n scope: null,\n scopePrefix: null,\n scopeDelimiter: null,\n state: null,\n requiredUrlParams: null,\n defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],\n responseType: 'code',\n responseParams: {\n code: 'code',\n clientId: 'clientId',\n redirectUri: 'redirectUri'\n },\n oauthType: '2.0',\n popupOptions: { width: null, height: null }\n };\n }\n\n init(options: IOAuth2Options, userData: any): angular.IPromise {\n return this.$q((resolve, reject) => {\n angular.extend(this.defaults, options);\n\n const stateName = this.defaults.name + '_state';\n const { name, state, popupOptions, redirectUri, responseType } = this.defaults;\n\n if (typeof state === 'function') {\n this.SatellizerStorage.set(stateName, state());\n } else if (typeof state === 'string') {\n this.SatellizerStorage.set(stateName, state);\n }\n\n const url = [this.defaults.authorizationEndpoint, this.buildQueryString()].join('?');\n\n this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then((oauth: any): void|angular.IPromise|angular.IHttpPromise => {\n if (responseType === 'token' || !url) {\n return resolve(oauth);\n }\n\n if (oauth.state && oauth.state !== this.SatellizerStorage.get(stateName)) {\n return reject(new Error(\n 'The value returned in the state parameter does not match the state value from your original ' +\n 'authorization code request.'\n ));\n }\n\n resolve(this.exchangeForToken(oauth, userData));\n }).catch(error => reject(error));\n });\n }\n\n exchangeForToken(oauthData: { code?, state? }, userData: any): angular.IHttpPromise {\n const payload = angular.extend({}, userData);\n\n angular.forEach(this.defaults.responseParams, (value, key) => {\n switch (key) {\n case 'code':\n payload[value] = oauthData.code;\n break;\n case 'clientId':\n payload[value] = this.defaults.clientId;\n break;\n case 'redirectUri':\n payload[value] = this.defaults.redirectUri;\n break;\n default:\n payload[value] = oauthData[key];\n }\n });\n\n if (oauthData.state) {\n payload.state = oauthData.state;\n }\n\n let exchangeForTokenUrl = this.SatellizerConfig.baseUrl ?\n joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) :\n this.defaults.url;\n\n return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials });\n }\n\n buildQueryString(): string {\n const keyValuePairs = [];\n const urlParamsCategories = ['defaultUrlParams', 'requiredUrlParams', 'optionalUrlParams'];\n\n angular.forEach(urlParamsCategories, (paramsCategory) => {\n angular.forEach(this.defaults[paramsCategory], (paramName) => {\n const camelizedName = OAuth2.camelCase(paramName);\n let paramValue = angular.isFunction(this.defaults[paramName]) ? this.defaults[paramName]() : this.defaults[camelizedName];\n\n if (paramName === 'redirect_uri' && !paramValue) {\n return;\n }\n if (paramName === 'state') {\n const stateName = this.defaults.name + '_state';\n paramValue = encodeURIComponent(this.SatellizerStorage.get(stateName));\n }\n if (paramName === 'scope' && Array.isArray(paramValue)) {\n paramValue = paramValue.join(this.defaults.scopeDelimiter);\n if (this.defaults.scopePrefix) {\n paramValue = [this.defaults.scopePrefix, paramValue].join(this.defaults.scopeDelimiter);\n }\n }\n\n keyValuePairs.push([paramName, paramValue]);\n });\n });\n\n return keyValuePairs.map(pair => pair.join('=')).join('&');\n }\n}\n","import { joinUrl } from './utils';\nimport Config from './config';\nimport Popup from './popup';\nimport Storage from './storage';\nimport Shared from './shared';\nimport OAuth1 from './oauth1';\nimport OAuth2 from './oauth2';\n\nexport default class OAuth {\n static $inject = [\n '$http',\n '$window',\n '$timeout',\n '$q',\n 'SatellizerConfig',\n 'SatellizerPopup',\n 'SatellizerStorage',\n 'SatellizerShared',\n 'SatellizerOAuth1',\n 'SatellizerOAuth2'\n ];\n\n constructor(private $http: angular.IHttpService,\n private $window: angular.IWindowService,\n private $timeout: angular.ITimeoutService,\n private $q: angular.IQService,\n private SatellizerConfig: Config,\n private SatellizerPopup: Popup,\n private SatellizerStorage: Storage,\n private SatellizerShared: Shared,\n private SatellizerOAuth1: OAuth1,\n private SatellizerOAuth2: OAuth2) {}\n\n authenticate(name: string, userData?: any): angular.IPromise {\n return this.$q((resolve, reject) => {\n const provider = this.SatellizerConfig.providers[name];\n\n let oauth = null;\n\n switch (provider.oauthType) {\n case '1.0':\n oauth = new OAuth1(this.$http, this.$window, this.SatellizerConfig, this.SatellizerPopup);\n break;\n case '2.0':\n oauth = new OAuth2(this.$http, this.$window, this.$timeout, this.$q, this.SatellizerConfig, this.SatellizerPopup, this.SatellizerStorage);\n break;\n default:\n return reject(new Error('Invalid OAuth Type'));\n }\n\n return oauth.init(provider, userData).then((response) => {\n if (provider.url) {\n this.SatellizerShared.setToken(response);\n }\n resolve(response);\n }).catch((error) => {\n reject(error);\n });\n });\n }\n\n unlink(provider: string, httpOptions: any = {}): angular.IHttpPromise {\n httpOptions.url = httpOptions.url ? httpOptions.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.unlinkUrl);\n httpOptions.data = { provider: provider } || httpOptions.data;\n httpOptions.method = httpOptions.method || 'POST';\n httpOptions.withCredentials = httpOptions.withCredentials || this.SatellizerConfig.withCredentials;\n\n return this.$http(httpOptions);\n }\n}\n","import Config from './config';\n\nexport default class Storage {\n static $inject = ['$window', 'SatellizerConfig'];\n\n private memoryStore: any;\n private storageType: string;\n\n constructor(private $window: angular.IHttpService,\n private SatellizerConfig: Config) {\n this.memoryStore = {};\n }\n\n get(key: string): string {\n try {\n return this.$window[this.SatellizerConfig.storageType].getItem(key);\n } catch (e) {\n return this.memoryStore[key];\n }\n }\n\n set(key: string, value: string): void {\n try {\n this.$window[this.SatellizerConfig.storageType].setItem(key, value);\n } catch (e) {\n this.memoryStore[key] = value;\n }\n }\n\n remove(key: string): void {\n try {\n this.$window[this.SatellizerConfig.storageType].removeItem(key);\n } catch (e) {\n delete this.memoryStore[key];\n }\n }\n}\n","import Config from './config';\nimport Shared from './shared';\nimport Storage from './storage';\n\nexport default class Interceptor implements angular.IHttpInterceptor {\n\n static $inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage'];\n\n static Factory(SatellizerConfig: Config, SatellizerShared: Shared, SatellizerStorage: Storage): Interceptor {\n return new Interceptor(SatellizerConfig, SatellizerShared, SatellizerStorage);\n }\n\n constructor(private SatellizerConfig: Config,\n private SatellizerShared: Shared,\n private SatellizerStorage: Storage) {\n }\n\n request = (config: angular.IRequestConfig): angular.IRequestConfig => {\n if (config['skipAuthorization']) {\n return config;\n }\n\n if (this.SatellizerShared.isAuthenticated() && this.SatellizerConfig.httpInterceptor()) {\n const tokenName = this.SatellizerConfig.tokenPrefix ?\n [this.SatellizerConfig.tokenPrefix, this.SatellizerConfig.tokenName].join('_') : this.SatellizerConfig.tokenName;\n let token = this.SatellizerStorage.get(tokenName);\n\n if (this.SatellizerConfig.tokenHeader && this.SatellizerConfig.tokenType) {\n token = this.SatellizerConfig.tokenType + ' ' + token;\n }\n\n config.headers[this.SatellizerConfig.tokenHeader] = token;\n }\n\n return config;\n };\n}\n\nInterceptor.Factory.$inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage'];","import Interceptor from './interceptor';\n\nexport default class HttpProviderConfig {\n static $inject = ['$httpProvider'];\n\n constructor(private $httpProvider: angular.IHttpProvider) {\n $httpProvider.interceptors.push(Interceptor.Factory);\n }\n}\n","import Config from './config';\nimport AuthProvider from './authProvider';\nimport Shared from './shared';\nimport Local from './local';\nimport Popup from './popup';\nimport OAuth from './oauth';\nimport OAuth2 from './oauth2';\nimport OAuth1 from './oauth1';\nimport Storage from './storage';\nimport Interceptor from './interceptor';\nimport HttpProviderConfig from './httpProviderConfig';\n\nangular.module('satellizer', [])\n .provider('$auth', ['SatellizerConfig', (SatellizerConfig) => new AuthProvider(SatellizerConfig)])\n .constant('SatellizerConfig', Config.getConstant)\n .service('SatellizerShared', Shared)\n .service('SatellizerLocal', Local)\n .service('SatellizerPopup', Popup)\n .service('SatellizerOAuth', OAuth)\n .service('SatellizerOAuth2', OAuth2)\n .service('SatellizerOAuth1', OAuth1)\n .service('SatellizerStorage', Storage)\n .service('SatellizerInterceptor', Interceptor)\n .config(['$httpProvider', ($httpProvider) => new HttpProviderConfig($httpProvider)]);\n\nexport default 'satellizer';\n\n"],"names":[],"mappings":";;;;;;;;;;;;IAAe;QAAA;YAKb,YAAO,GAAG,GAAG,CAAC;YACd,aAAQ,GAAG,aAAa,CAAC;YACzB,cAAS,GAAG,cAAc,CAAC;YAC3B,cAAS,GAAG,eAAe,CAAC;YAC5B,cAAS,GAAG,OAAO,CAAC;YACpB,gBAAW,GAAG,YAAY,CAAC;YAC3B,gBAAW,GAAG,eAAe,CAAC;YAC9B,cAAS,GAAG,QAAQ,CAAC;YACrB,gBAAW,GAAG,cAAc,CAAC;YAC7B,cAAS,GAAG,IAAI,CAAC;YACjB,oBAAe,GAAG,KAAK,CAAC;YACxB,cAAS,GAAG;gBACV,QAAQ,EAAE;oBACR,IAAI,EAAE,UAAU;oBAChB,GAAG,EAAE,gBAAgB;oBACrB,qBAAqB,EAAE,4CAA4C;oBACnE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG;oBACzC,iBAAiB,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;oBACvC,KAAK,EAAE,CAAC,OAAO,CAAC;oBAChB,cAAc,EAAE,GAAG;oBACnB,OAAO,EAAE,OAAO;oBAChB,SAAS,EAAE,KAAK;oBAChB,YAAY,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,E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O,GAAG,CAAC,eAAe,CAAC,CAAC;QAKrC,yBAAC;AAAD,IAAA,CAAC,IAAA,AAED;;ICEA,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;SAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,kBAAkB,EAAE,UAAC,gBAAgB,IAAK,OAAA,IAAI,YAAY,CAAC,gBAAgB,CAAC,GAAA,CAAC,CAAC;SACjG,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC,WAAW,CAAC;SAChD,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;SACjC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;SACnC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC;SACrC,OAAO,CAAC,uBAAuB,EAAE,WAAW,CAAC;SAC7C,MAAM,CAAC,CAAC,eAAe,EAAE,UAAC,aAAa,IAAK,OAAA,IAAI,kBAAkB,CAAC,aAAa,CAAC,GAAA,CAAC,CAAC,CAAC;AAEvF,cAAe,YAAY,CAAC;;;;"} \ No newline at end of file diff --git a/dist/satellizer.min.js b/dist/satellizer.min.js index 2e647daa..c855a9e5 100644 --- a/dist/satellizer.min.js +++ b/dist/satellizer.min.js @@ -1 +1,6 @@ -(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.satellizer=factory()})(this,function(){"use strict";var Config=function(){function Config(){this.baseUrl="/";this.loginUrl="/auth/login";this.signupUrl="/auth/signup";this.unlinkUrl="/auth/unlink/";this.tokenName="token";this.tokenPrefix="satellizer";this.tokenHeader="Authorization";this.tokenType="Bearer";this.storageType="localStorage";this.tokenRoot=null;this.withCredentials=false;this.providers={facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:window.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:window.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display","state"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633},state:function(){return encodeURIComponent(Math.random().toString(36).substr(2))}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:window.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:window.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:window.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:window.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:window.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:window.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:window.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:window.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}},spotify:{name:"spotify",url:"/auth/spotify",authorizationEndpoint:"https://accounts.spotify.com/authorize",redirectUri:window.location.origin,optionalUrlParams:["state"],requiredUrlParams:["scope"],scope:["user-read-email"],scopePrefix:"",scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:500,height:530},state:function(){return encodeURIComponent(Math.random().toString(36).substr(2))}}};this.httpInterceptor=function(){return true}}Object.defineProperty(Config,"getConstant",{get:function(){return new Config},enumerable:true,configurable:true});return Config}();var AuthProvider=function(){function AuthProvider(SatellizerConfig){this.SatellizerConfig=SatellizerConfig}Object.defineProperty(AuthProvider.prototype,"baseUrl",{get:function(){return this.SatellizerConfig.baseUrl},set:function(value){this.SatellizerConfig.baseUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"loginUrl",{get:function(){return this.SatellizerConfig.loginUrl},set:function(value){this.SatellizerConfig.loginUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"signupUrl",{get:function(){return this.SatellizerConfig.signupUrl},set:function(value){this.SatellizerConfig.signupUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"unlinkUrl",{get:function(){return this.SatellizerConfig.unlinkUrl},set:function(value){this.SatellizerConfig.unlinkUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenRoot",{get:function(){return this.SatellizerConfig.tokenRoot},set:function(value){this.SatellizerConfig.tokenRoot=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenName",{get:function(){return this.SatellizerConfig.tokenName},set:function(value){this.SatellizerConfig.tokenName=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenPrefix",{get:function(){return this.SatellizerConfig.tokenPrefix},set:function(value){this.SatellizerConfig.tokenPrefix=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenHeader",{get:function(){return this.SatellizerConfig.tokenHeader},set:function(value){this.SatellizerConfig.tokenHeader=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenType",{get:function(){return this.SatellizerConfig.tokenType},set:function(value){this.SatellizerConfig.tokenType=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"withCredentials",{get:function(){return this.SatellizerConfig.withCredentials},set:function(value){this.SatellizerConfig.withCredentials=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"storageType",{get:function(){return this.SatellizerConfig.storageType},set:function(value){this.SatellizerConfig.storageType=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"httpInterceptor",{get:function(){return this.SatellizerConfig.httpInterceptor},set:function(value){if(typeof value==="function"){this.SatellizerConfig.httpInterceptor=value}else{this.SatellizerConfig.httpInterceptor=function(){return value}}},enumerable:true,configurable:true});AuthProvider.prototype.facebook=function(options){angular.extend(this.SatellizerConfig.providers.facebook,options)};AuthProvider.prototype.google=function(options){angular.extend(this.SatellizerConfig.providers.google,options)};AuthProvider.prototype.github=function(options){angular.extend(this.SatellizerConfig.providers.github,options)};AuthProvider.prototype.instagram=function(options){angular.extend(this.SatellizerConfig.providers.instagram,options)};AuthProvider.prototype.linkedin=function(options){angular.extend(this.SatellizerConfig.providers.linkedin,options)};AuthProvider.prototype.twitter=function(options){angular.extend(this.SatellizerConfig.providers.twitter,options)};AuthProvider.prototype.twitch=function(options){angular.extend(this.SatellizerConfig.providers.twitch,options)};AuthProvider.prototype.live=function(options){angular.extend(this.SatellizerConfig.providers.live,options)};AuthProvider.prototype.yahoo=function(options){angular.extend(this.SatellizerConfig.providers.yahoo,options)};AuthProvider.prototype.bitbucket=function(options){angular.extend(this.SatellizerConfig.providers.bitbucket,options)};AuthProvider.prototype.spotify=function(options){angular.extend(this.SatellizerConfig.providers.spotify,options)};AuthProvider.prototype.oauth1=function(options){this.SatellizerConfig.providers[options.name]=angular.extend(options,{oauthType:"1.0"})};AuthProvider.prototype.oauth2=function(options){this.SatellizerConfig.providers[options.name]=angular.extend(options,{oauthType:"2.0"})};AuthProvider.prototype.$get=function(SatellizerShared,SatellizerLocal,SatellizerOAuth){return{login:function(user,options){return SatellizerLocal.login(user,options)},signup:function(user,options){return SatellizerLocal.signup(user,options)},logout:function(){return SatellizerShared.logout()},authenticate:function(name,data){return SatellizerOAuth.authenticate(name,data)},link:function(name,data){return SatellizerOAuth.authenticate(name,data)},unlink:function(name,options){return SatellizerOAuth.unlink(name,options)},isAuthenticated:function(){return SatellizerShared.isAuthenticated()},getPayload:function(){return SatellizerShared.getPayload()},getToken:function(){return SatellizerShared.getToken()},setToken:function(token){return SatellizerShared.setToken({access_token:token})},removeToken:function(){return SatellizerShared.removeToken()},setStorageType:function(type){return SatellizerShared.setStorageType(type)}}};AuthProvider.$inject=["SatellizerConfig"];return AuthProvider}();AuthProvider.prototype.$get.$inject=["SatellizerShared","SatellizerLocal","SatellizerOAuth"];function joinUrl(baseUrl,url){if(/^(?:[a-z]+:)?\/\//i.test(url)){return url}var joined=[baseUrl,url].join("/");var normalize=function(str){return str.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return normalize(joined)}function getFullUrlPath(location){var isHttps=location.protocol==="https:";return location.protocol+"//"+location.hostname+":"+(location.port||(isHttps?"443":"80"))+(/^\//.test(location.pathname)?location.pathname:"/"+location.pathname)}function parseQueryString(str){var obj={};var key;var value;angular.forEach((str||"").split("&"),function(keyValue){if(keyValue){value=keyValue.split("=");key=decodeURIComponent(value[0]);obj[key]=angular.isDefined(value[1])?decodeURIComponent(value[1]):true}});return obj}function decodeBase64(str){var buffer;if(typeof module!=="undefined"&&module.exports){try{buffer=require("buffer").Buffer}catch(err){}}var fromCharCode=String.fromCharCode;var re_btou=new RegExp(["[À-ß][€-¿]","[à-ï][€-¿]{2}","[ð-÷][€-¿]{3}"].join("|"),"g");var cb_btou=function(cccc){switch(cccc.length){case 4:var cp=(7&cccc.charCodeAt(0))<<18|(63&cccc.charCodeAt(1))<<12|(63&cccc.charCodeAt(2))<<6|63&cccc.charCodeAt(3);var offset=cp-65536;return fromCharCode((offset>>>10)+55296)+fromCharCode((offset&1023)+56320);case 3:return fromCharCode((15&cccc.charCodeAt(0))<<12|(63&cccc.charCodeAt(1))<<6|63&cccc.charCodeAt(2));default:return fromCharCode((31&cccc.charCodeAt(0))<<6|63&cccc.charCodeAt(1))}};var btou=function(b){return b.replace(re_btou,cb_btou)};var _decode=buffer?function(a){return(a.constructor===buffer.constructor?a:new buffer(a,"base64")).toString()}:function(a){return btou(atob(a))};return _decode(String(str).replace(/[-_]/g,function(m0){return m0==="-"?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))}var Shared=function(){function Shared($q,$window,SatellizerConfig,SatellizerStorage){this.$q=$q;this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.SatellizerStorage=SatellizerStorage;var _a=this.SatellizerConfig,tokenName=_a.tokenName,tokenPrefix=_a.tokenPrefix;this.prefixedTokenName=tokenPrefix?[tokenPrefix,tokenName].join("_"):tokenName}Shared.prototype.getToken=function(){return this.SatellizerStorage.get(this.prefixedTokenName)};Shared.prototype.getPayload=function(){var token=this.SatellizerStorage.get(this.prefixedTokenName);if(token&&token.split(".").length===3){try{var base64Url=token.split(".")[1];var base64=base64Url.replace("-","+").replace("_","/");return JSON.parse(decodeBase64(base64))}catch(e){}}};Shared.prototype.setToken=function(response){var tokenRoot=this.SatellizerConfig.tokenRoot;var tokenName=this.SatellizerConfig.tokenName;var accessToken=response&&response.access_token;var token;if(accessToken){if(angular.isObject(accessToken)&&angular.isObject(accessToken.data)){response=accessToken}else if(angular.isString(accessToken)){token=accessToken}}if(!token&&response){var tokenRootData=tokenRoot&&tokenRoot.split(".").reduce(function(o,x){return o[x]},response.data);token=tokenRootData?tokenRootData[tokenName]:response.data&&response.data[tokenName]}if(token){this.SatellizerStorage.set(this.prefixedTokenName,token)}};Shared.prototype.removeToken=function(){this.SatellizerStorage.remove(this.prefixedTokenName)};Shared.prototype.isAuthenticated=function(){var token=this.SatellizerStorage.get(this.prefixedTokenName);if(token){if(token.split(".").length===3){try{var base64Url=token.split(".")[1];var base64=base64Url.replace("-","+").replace("_","/");var exp=JSON.parse(this.$window.atob(base64)).exp;if(typeof exp==="number"){return Math.round((new Date).getTime()/1e3)-1?"_blank":name;this.popup=window.open(this.url,popupName,options);if(this.popup&&this.popup.focus){this.popup.focus()}};Popup.prototype.polling=function(redirectUri){var _this=this;return this.$q(function(resolve,reject){var redirectUriParser=document.createElement("a");redirectUriParser.href=redirectUri;var redirectUriPath=getFullUrlPath(redirectUriParser);var polling=_this.$interval(function(){if(!_this.popup||_this.popup.closed||_this.popup.closed===undefined){_this.$interval.cancel(polling);reject(new Error("The popup window was closed"))}try{var popupWindowPath=getFullUrlPath(_this.popup.location);if(popupWindowPath===redirectUriPath){if(_this.popup.location.search||_this.popup.location.hash){var query=parseQueryString(_this.popup.location.search.substring(1).replace(/\/$/,""));var hash=parseQueryString(_this.popup.location.hash.substring(1).replace(/[\/$]/,""));var params=angular.extend({},query,hash);if(params.error){reject(new Error(params.error))}else{resolve(params)}}else{reject(new Error("OAuth redirect has occurred but no query or hash parameters were found. "+"They were either not set during the redirect, or were removed—typically by a "+"routing library—before Satellizer could read it."))}_this.$interval.cancel(polling);_this.popup.close()}}catch(error){}},500)})};Popup.prototype.eventListener=function(redirectUri){var _this=this;return this.$q(function(resolve,reject){_this.popup.addEventListener("loadstart",function(event){if(!event.url.includes(redirectUri)){return}var parser=document.createElement("a");parser.href=event.url;if(parser.search||parser.hash){var query=parseQueryString(parser.search.substring(1).replace(/\/$/,""));var hash=parseQueryString(parser.hash.substring(1).replace(/[\/$]/,""));var params=angular.extend({},query,hash);if(params.error){reject(new Error(params.error))}else{resolve(params)}_this.popup.close()}});_this.popup.addEventListener("loaderror",function(){reject(new Error("Authorization failed"))});_this.popup.addEventListener("exit",function(){reject(new Error("The popup window was closed"))})})};Popup.$inject=["$interval","$window","$q"];return Popup}();var OAuth1=function(){function OAuth1($http,$window,SatellizerConfig,SatellizerPopup){this.$http=$http;this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.defaults={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{width:null,height:null}}}OAuth1.prototype.init=function(options,userData){var _this=this;angular.extend(this.defaults,options);if(!this.$window["cordova"]){this.SatellizerPopup.open("about:blank",options.name,options.popupOptions)}return this.getRequestToken().then(function(response){return _this.openPopup(options,response).then(function(popupResponse){return _this.exchangeForToken(popupResponse,userData)})})};OAuth1.prototype.openPopup=function(options,response){var popupUrl=[options.authorizationEndpoint,this.buildQueryString(response.data)].join("?");if(this.$window["cordova"]){this.SatellizerPopup.open(popupUrl,options.name,options.popupOptions);return this.SatellizerPopup.eventListener(this.defaults.redirectUri)}else{this.SatellizerPopup.popup.location=popupUrl;return this.SatellizerPopup.polling(this.defaults.redirectUri)}};OAuth1.prototype.getRequestToken=function(){var url=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(url,this.defaults)};OAuth1.prototype.exchangeForToken=function(oauthData,userData){var payload=angular.extend({},userData,oauthData);var exchangeForTokenUrl=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(exchangeForTokenUrl,payload,{withCredentials:this.SatellizerConfig.withCredentials})};OAuth1.prototype.buildQueryString=function(obj){var str=[];angular.forEach(obj,function(value,key){str.push(encodeURIComponent(key)+"="+encodeURIComponent(value))});return str.join("&")};OAuth1.$inject=["$http","$window","SatellizerConfig","SatellizerPopup"];return OAuth1}();var OAuth2=function(){function OAuth2($http,$window,$timeout,$q,SatellizerConfig,SatellizerPopup,SatellizerStorage){this.$http=$http;this.$window=$window;this.$timeout=$timeout;this.$q=$q;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.SatellizerStorage=SatellizerStorage;this.defaults={name:null,url:null,clientId:null,authorizationEndpoint:null,redirectUri:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,requiredUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},oauthType:"2.0",popupOptions:{width:null,height:null}}}OAuth2.camelCase=function(name){return name.replace(/([\:\-\_]+(.))/g,function(_,separator,letter,offset){return offset?letter.toUpperCase():letter})};OAuth2.prototype.init=function(options,userData){var _this=this;return this.$q(function(resolve,reject){angular.extend(_this.defaults,options);_this.$timeout(function(){var stateName=_this.defaults.name+"_state";var _a=_this.defaults,name=_a.name,state=_a.state,popupOptions=_a.popupOptions,redirectUri=_a.redirectUri,responseType=_a.responseType;if(typeof state==="function"){_this.SatellizerStorage.set(stateName,state())}else if(typeof state==="string"){_this.SatellizerStorage.set(stateName,state)}var url=[_this.defaults.authorizationEndpoint,_this.buildQueryString()].join("?");_this.SatellizerPopup.open(url,name,popupOptions);_this.SatellizerPopup.polling(redirectUri).then(function(oauth){if(responseType==="token"||!url){return resolve(oauth)}if(oauth.state&&oauth.state!==_this.SatellizerStorage.get(stateName)){return reject(new Error("The value returned in the state parameter does not match the state value from your original "+"authorization code request."))}resolve(_this.exchangeForToken(oauth,userData))}).catch(function(error){return reject(error)})})})};OAuth2.prototype.exchangeForToken=function(oauthData,userData){var _this=this;var payload=angular.extend({},userData);angular.forEach(this.defaults.responseParams,function(value,key){switch(key){case"code":payload[value]=oauthData.code;break;case"clientId":payload[value]=_this.defaults.clientId;break;case"redirectUri":payload[value]=_this.defaults.redirectUri;break;default:payload[value]=oauthData[key]}});if(oauthData.state){payload.state=oauthData.state}var exchangeForTokenUrl=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(exchangeForTokenUrl,payload,{withCredentials:this.SatellizerConfig.withCredentials})};OAuth2.prototype.buildQueryString=function(){var _this=this;var keyValuePairs=[];var urlParamsCategories=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];angular.forEach(urlParamsCategories,function(paramsCategory){angular.forEach(_this.defaults[paramsCategory],function(paramName){var camelizedName=OAuth2.camelCase(paramName);var paramValue=angular.isFunction(_this.defaults[paramName])?_this.defaults[paramName]():_this.defaults[camelizedName];if(paramName==="redirect_uri"&&!paramValue){return}if(paramName==="state"){var stateName=_this.defaults.name+"_state";paramValue=encodeURIComponent(_this.SatellizerStorage.get(stateName))}if(paramName==="scope"&&Array.isArray(paramValue)){paramValue=paramValue.join(_this.defaults.scopeDelimiter);if(_this.defaults.scopePrefix){paramValue=[_this.defaults.scopePrefix,paramValue].join(_this.defaults.scopeDelimiter)}}keyValuePairs.push([paramName,paramValue])})});return keyValuePairs.map(function(pair){return pair.join("=")}).join("&")};OAuth2.$inject=["$http","$window","$timeout","$q","SatellizerConfig","SatellizerPopup","SatellizerStorage"];return OAuth2}();var OAuth=function(){function OAuth($http,$window,$timeout,$q,SatellizerConfig,SatellizerPopup,SatellizerStorage,SatellizerShared,SatellizerOAuth1,SatellizerOAuth2){this.$http=$http;this.$window=$window;this.$timeout=$timeout;this.$q=$q;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.SatellizerStorage=SatellizerStorage;this.SatellizerShared=SatellizerShared;this.SatellizerOAuth1=SatellizerOAuth1;this.SatellizerOAuth2=SatellizerOAuth2}OAuth.prototype.authenticate=function(name,userData){var _this=this;return this.$q(function(resolve,reject){var provider=_this.SatellizerConfig.providers[name];var oauth=null;switch(provider.oauthType){case"1.0":oauth=new OAuth1(_this.$http,_this.$window,_this.SatellizerConfig,_this.SatellizerPopup);break;case"2.0":oauth=new OAuth2(_this.$http,_this.$window,_this.$timeout,_this.$q,_this.SatellizerConfig,_this.SatellizerPopup,_this.SatellizerStorage);break;default:return reject(new Error("Invalid OAuth Type"))}return oauth.init(provider,userData).then(function(response){if(provider.url){_this.SatellizerShared.setToken(response)}resolve(response)}).catch(function(error){reject(error)})})};OAuth.prototype.unlink=function(provider,httpOptions){if(httpOptions===void 0){httpOptions={}}httpOptions.url=httpOptions.url?httpOptions.url:joinUrl(this.SatellizerConfig.baseUrl,this.SatellizerConfig.unlinkUrl);httpOptions.data={provider:provider}||httpOptions.data;httpOptions.method=httpOptions.method||"POST";httpOptions.withCredentials=httpOptions.withCredentials||this.SatellizerConfig.withCredentials;return this.$http(httpOptions)};OAuth.$inject=["$http","$window","$timeout","$q","SatellizerConfig","SatellizerPopup","SatellizerStorage","SatellizerShared","SatellizerOAuth1","SatellizerOAuth2"];return OAuth}();var Storage=function(){function Storage($window,SatellizerConfig){this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.memoryStore={}}Storage.prototype.get=function(key){try{return this.$window[this.SatellizerConfig.storageType].getItem(key)}catch(e){return this.memoryStore[key]}};Storage.prototype.set=function(key,value){try{this.$window[this.SatellizerConfig.storageType].setItem(key,value)}catch(e){this.memoryStore[key]=value}};Storage.prototype.remove=function(key){try{this.$window[this.SatellizerConfig.storageType].removeItem(key)}catch(e){delete this.memoryStore[key]}};Storage.$inject=["$window","SatellizerConfig"];return Storage}();var Interceptor=function(){function Interceptor(SatellizerConfig,SatellizerShared,SatellizerStorage){var _this=this;this.SatellizerConfig=SatellizerConfig;this.SatellizerShared=SatellizerShared;this.SatellizerStorage=SatellizerStorage;this.request=function(config){if(config["skipAuthorization"]){return config}if(_this.SatellizerShared.isAuthenticated()&&_this.SatellizerConfig.httpInterceptor()){var tokenName=_this.SatellizerConfig.tokenPrefix?[_this.SatellizerConfig.tokenPrefix,_this.SatellizerConfig.tokenName].join("_"):_this.SatellizerConfig.tokenName;var token=_this.SatellizerStorage.get(tokenName);if(_this.SatellizerConfig.tokenHeader&&_this.SatellizerConfig.tokenType){token=_this.SatellizerConfig.tokenType+" "+token}config.headers[_this.SatellizerConfig.tokenHeader]=token}return config}}Interceptor.Factory=function(SatellizerConfig,SatellizerShared,SatellizerStorage){return new Interceptor(SatellizerConfig,SatellizerShared,SatellizerStorage)};Interceptor.$inject=["SatellizerConfig","SatellizerShared","SatellizerStorage"];return Interceptor}();Interceptor.Factory.$inject=["SatellizerConfig","SatellizerShared","SatellizerStorage"];var HttpProviderConfig=function(){function HttpProviderConfig($httpProvider){this.$httpProvider=$httpProvider;$httpProvider.interceptors.push(Interceptor.Factory)}HttpProviderConfig.$inject=["$httpProvider"];return HttpProviderConfig}();angular.module("satellizer",[]).provider("$auth",["SatellizerConfig",function(SatellizerConfig){return new AuthProvider(SatellizerConfig)}]).constant("SatellizerConfig",Config.getConstant).service("SatellizerShared",Shared).service("SatellizerLocal",Local).service("SatellizerPopup",Popup).service("SatellizerOAuth",OAuth).service("SatellizerOAuth2",OAuth2).service("SatellizerOAuth1",OAuth1).service("SatellizerStorage",Storage).service("SatellizerInterceptor",Interceptor).config(["$httpProvider",function($httpProvider){return new HttpProviderConfig($httpProvider)}]);var ng1="satellizer";return ng1}); \ No newline at end of file +/** + * Satellizer 0.15.5 + * (c) 2016 Sahat Yalkabov + * License: MIT + */ +(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.satellizer=factory()})(this,function(){"use strict";var Config=function(){function Config(){this.baseUrl="/";this.loginUrl="/auth/login";this.signupUrl="/auth/signup";this.unlinkUrl="/auth/unlink/";this.tokenName="token";this.tokenPrefix="satellizer";this.tokenHeader="Authorization";this.tokenType="Bearer";this.storageType="localStorage";this.tokenRoot=null;this.withCredentials=false;this.providers={facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:window.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:window.location.origin,requiredUrlParams:["scope"],optionalUrlParams:["display","state"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633},state:function(){return encodeURIComponent(Math.random().toString(36).substr(2))}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:window.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:window.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:window.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:window.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:window.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:window.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:window.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:window.location.origin+"/",requiredUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1028,height:529}},spotify:{name:"spotify",url:"/auth/spotify",authorizationEndpoint:"https://accounts.spotify.com/authorize",redirectUri:window.location.origin,optionalUrlParams:["state"],requiredUrlParams:["scope"],scope:["user-read-email"],scopePrefix:"",scopeDelimiter:",",oauthType:"2.0",popupOptions:{width:500,height:530},state:function(){return encodeURIComponent(Math.random().toString(36).substr(2))}}};this.httpInterceptor=function(){return true}}Object.defineProperty(Config,"getConstant",{get:function(){return new Config},enumerable:true,configurable:true});return Config}();var AuthProvider=function(){function AuthProvider(SatellizerConfig){this.SatellizerConfig=SatellizerConfig}Object.defineProperty(AuthProvider.prototype,"baseUrl",{get:function(){return this.SatellizerConfig.baseUrl},set:function(value){this.SatellizerConfig.baseUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"loginUrl",{get:function(){return this.SatellizerConfig.loginUrl},set:function(value){this.SatellizerConfig.loginUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"signupUrl",{get:function(){return this.SatellizerConfig.signupUrl},set:function(value){this.SatellizerConfig.signupUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"unlinkUrl",{get:function(){return this.SatellizerConfig.unlinkUrl},set:function(value){this.SatellizerConfig.unlinkUrl=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenRoot",{get:function(){return this.SatellizerConfig.tokenRoot},set:function(value){this.SatellizerConfig.tokenRoot=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenName",{get:function(){return this.SatellizerConfig.tokenName},set:function(value){this.SatellizerConfig.tokenName=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenPrefix",{get:function(){return this.SatellizerConfig.tokenPrefix},set:function(value){this.SatellizerConfig.tokenPrefix=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenHeader",{get:function(){return this.SatellizerConfig.tokenHeader},set:function(value){this.SatellizerConfig.tokenHeader=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"tokenType",{get:function(){return this.SatellizerConfig.tokenType},set:function(value){this.SatellizerConfig.tokenType=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"withCredentials",{get:function(){return this.SatellizerConfig.withCredentials},set:function(value){this.SatellizerConfig.withCredentials=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"storageType",{get:function(){return this.SatellizerConfig.storageType},set:function(value){this.SatellizerConfig.storageType=value},enumerable:true,configurable:true});Object.defineProperty(AuthProvider.prototype,"httpInterceptor",{get:function(){return this.SatellizerConfig.httpInterceptor},set:function(value){if(typeof value==="function"){this.SatellizerConfig.httpInterceptor=value}else{this.SatellizerConfig.httpInterceptor=function(){return value}}},enumerable:true,configurable:true});AuthProvider.prototype.facebook=function(options){angular.extend(this.SatellizerConfig.providers.facebook,options)};AuthProvider.prototype.google=function(options){angular.extend(this.SatellizerConfig.providers.google,options)};AuthProvider.prototype.github=function(options){angular.extend(this.SatellizerConfig.providers.github,options)};AuthProvider.prototype.instagram=function(options){angular.extend(this.SatellizerConfig.providers.instagram,options)};AuthProvider.prototype.linkedin=function(options){angular.extend(this.SatellizerConfig.providers.linkedin,options)};AuthProvider.prototype.twitter=function(options){angular.extend(this.SatellizerConfig.providers.twitter,options)};AuthProvider.prototype.twitch=function(options){angular.extend(this.SatellizerConfig.providers.twitch,options)};AuthProvider.prototype.live=function(options){angular.extend(this.SatellizerConfig.providers.live,options)};AuthProvider.prototype.yahoo=function(options){angular.extend(this.SatellizerConfig.providers.yahoo,options)};AuthProvider.prototype.bitbucket=function(options){angular.extend(this.SatellizerConfig.providers.bitbucket,options)};AuthProvider.prototype.spotify=function(options){angular.extend(this.SatellizerConfig.providers.spotify,options)};AuthProvider.prototype.oauth1=function(options){this.SatellizerConfig.providers[options.name]=angular.extend(options,{oauthType:"1.0"})};AuthProvider.prototype.oauth2=function(options){this.SatellizerConfig.providers[options.name]=angular.extend(options,{oauthType:"2.0"})};AuthProvider.prototype.$get=function(SatellizerShared,SatellizerLocal,SatellizerOAuth){return{login:function(user,options){return SatellizerLocal.login(user,options)},signup:function(user,options){return SatellizerLocal.signup(user,options)},logout:function(){return SatellizerShared.logout()},authenticate:function(name,data){return SatellizerOAuth.authenticate(name,data)},link:function(name,data){return SatellizerOAuth.authenticate(name,data)},unlink:function(name,options){return SatellizerOAuth.unlink(name,options)},isAuthenticated:function(){return SatellizerShared.isAuthenticated()},getPayload:function(){return SatellizerShared.getPayload()},getToken:function(){return SatellizerShared.getToken()},setToken:function(token){return SatellizerShared.setToken({access_token:token})},removeToken:function(){return SatellizerShared.removeToken()},setStorageType:function(type){return SatellizerShared.setStorageType(type)}}};AuthProvider.$inject=["SatellizerConfig"];return AuthProvider}();AuthProvider.prototype.$get.$inject=["SatellizerShared","SatellizerLocal","SatellizerOAuth"];function joinUrl(baseUrl,url){if(/^(?:[a-z]+:)?\/\//i.test(url)){return url}var joined=[baseUrl,url].join("/");var normalize=function(str){return str.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")};return normalize(joined)}function getFullUrlPath(location){var isHttps=location.protocol==="https:";return location.protocol+"//"+location.hostname+":"+(location.port||(isHttps?"443":"80"))+(/^\//.test(location.pathname)?location.pathname:"/"+location.pathname)}function parseQueryString(str){var obj={};var key;var value;angular.forEach((str||"").split("&"),function(keyValue){if(keyValue){value=keyValue.split("=");key=decodeURIComponent(value[0]);obj[key]=angular.isDefined(value[1])?decodeURIComponent(value[1]):true}});return obj}function decodeBase64(str){var buffer;if(typeof module!=="undefined"&&module.exports){try{buffer=require("buffer").Buffer}catch(err){}}var fromCharCode=String.fromCharCode;var re_btou=new RegExp(["[À-ß][€-¿]","[à-ï][€-¿]{2}","[ð-÷][€-¿]{3}"].join("|"),"g");var cb_btou=function(cccc){switch(cccc.length){case 4:var cp=(7&cccc.charCodeAt(0))<<18|(63&cccc.charCodeAt(1))<<12|(63&cccc.charCodeAt(2))<<6|63&cccc.charCodeAt(3);var offset=cp-65536;return fromCharCode((offset>>>10)+55296)+fromCharCode((offset&1023)+56320);case 3:return fromCharCode((15&cccc.charCodeAt(0))<<12|(63&cccc.charCodeAt(1))<<6|63&cccc.charCodeAt(2));default:return fromCharCode((31&cccc.charCodeAt(0))<<6|63&cccc.charCodeAt(1))}};var btou=function(b){return b.replace(re_btou,cb_btou)};var _decode=buffer?function(a){return(a.constructor===buffer.constructor?a:new buffer(a,"base64")).toString()}:function(a){return btou(atob(a))};return _decode(String(str).replace(/[-_]/g,function(m0){return m0==="-"?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))}var Shared=function(){function Shared($q,$window,SatellizerConfig,SatellizerStorage){this.$q=$q;this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.SatellizerStorage=SatellizerStorage;var _a=this.SatellizerConfig,tokenName=_a.tokenName,tokenPrefix=_a.tokenPrefix;this.prefixedTokenName=tokenPrefix?[tokenPrefix,tokenName].join("_"):tokenName}Shared.prototype.getToken=function(){return this.SatellizerStorage.get(this.prefixedTokenName)};Shared.prototype.getPayload=function(){var token=this.SatellizerStorage.get(this.prefixedTokenName);if(token&&token.split(".").length===3){try{var base64Url=token.split(".")[1];var base64=base64Url.replace("-","+").replace("_","/");return JSON.parse(decodeBase64(base64))}catch(e){}}};Shared.prototype.setToken=function(response){var tokenRoot=this.SatellizerConfig.tokenRoot;var tokenName=this.SatellizerConfig.tokenName;var accessToken=response&&response.access_token;var token;if(accessToken){if(angular.isObject(accessToken)&&angular.isObject(accessToken.data)){response=accessToken}else if(angular.isString(accessToken)){token=accessToken}}if(!token&&response){var tokenRootData=tokenRoot&&tokenRoot.split(".").reduce(function(o,x){return o[x]},response.data);token=tokenRootData?tokenRootData[tokenName]:response.data&&response.data[tokenName]}if(token){this.SatellizerStorage.set(this.prefixedTokenName,token)}};Shared.prototype.removeToken=function(){this.SatellizerStorage.remove(this.prefixedTokenName)};Shared.prototype.isAuthenticated=function(){var token=this.SatellizerStorage.get(this.prefixedTokenName);if(token){if(token.split(".").length===3){try{var base64Url=token.split(".")[1];var base64=base64Url.replace("-","+").replace("_","/");var exp=JSON.parse(this.$window.atob(base64)).exp;if(typeof exp==="number"){return Math.round((new Date).getTime()/1e3)-1?"_blank":name;this.popup=this.$window.open(url,popupName,options);if(this.popup&&this.popup.focus){this.popup.focus()}if(dontPoll){return}if(this.$window["cordova"]){return this.eventListener(redirectUri)}else{if(url==="about:blank"){this.popup.location=url}return this.polling(redirectUri)}};Popup.prototype.polling=function(redirectUri){var _this=this;return this.$q(function(resolve,reject){var redirectUriParser=document.createElement("a");redirectUriParser.href=redirectUri;var redirectUriPath=getFullUrlPath(redirectUriParser);var polling=_this.$interval(function(){if(!_this.popup||_this.popup.closed||_this.popup.closed===undefined){_this.$interval.cancel(polling);reject(new Error("The popup window was closed"))}try{var popupWindowPath=getFullUrlPath(_this.popup.location);if(popupWindowPath===redirectUriPath){if(_this.popup.location.search||_this.popup.location.hash){var query=parseQueryString(_this.popup.location.search.substring(1).replace(/\/$/,""));var hash=parseQueryString(_this.popup.location.hash.substring(1).replace(/[\/$]/,""));var params=angular.extend({},query,hash);if(params.error){reject(new Error(params.error))}else{resolve(params)}}else{reject(new Error("OAuth redirect has occurred but no query or hash parameters were found. "+"They were either not set during the redirect, or were removed—typically by a "+"routing library—before Satellizer could read it."))}_this.$interval.cancel(polling);_this.popup.close()}}catch(error){}},500)})};Popup.prototype.eventListener=function(redirectUri){var _this=this;return this.$q(function(resolve,reject){_this.popup.addEventListener("loadstart",function(event){if(event.url.indexOf(redirectUri)!==0){return}var parser=document.createElement("a");parser.href=event.url;if(parser.search||parser.hash){var query=parseQueryString(parser.search.substring(1).replace(/\/$/,""));var hash=parseQueryString(parser.hash.substring(1).replace(/[\/$]/,""));var params=angular.extend({},query,hash);if(params.error){reject(new Error(params.error))}else{resolve(params)}_this.popup.close()}});_this.popup.addEventListener("loaderror",function(){reject(new Error("Authorization failed"))});_this.popup.addEventListener("exit",function(){reject(new Error("The popup window was closed"))})})};Popup.$inject=["$interval","$window","$q"];return Popup}();var OAuth1=function(){function OAuth1($http,$window,SatellizerConfig,SatellizerPopup){this.$http=$http;this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.defaults={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{width:null,height:null}}}OAuth1.prototype.init=function(options,userData){var _this=this;angular.extend(this.defaults,options);var name=options.name,popupOptions=options.popupOptions;var redirectUri=this.defaults.redirectUri;if(!this.$window["cordova"]){this.SatellizerPopup.open("about:blank",name,popupOptions,redirectUri,true)}return this.getRequestToken().then(function(response){return _this.openPopup(options,response).then(function(popupResponse){return _this.exchangeForToken(popupResponse,userData)})})};OAuth1.prototype.openPopup=function(options,response){var url=[options.authorizationEndpoint,this.buildQueryString(response.data)].join("?");var redirectUri=this.defaults.redirectUri;if(this.$window["cordova"]){return this.SatellizerPopup.open(url,options.name,options.popupOptions,redirectUri)}else{this.SatellizerPopup.popup.location=url;return this.SatellizerPopup.polling(redirectUri)}};OAuth1.prototype.getRequestToken=function(){var url=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(url,this.defaults)};OAuth1.prototype.exchangeForToken=function(oauthData,userData){var payload=angular.extend({},userData,oauthData);var exchangeForTokenUrl=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(exchangeForTokenUrl,payload,{withCredentials:this.SatellizerConfig.withCredentials})};OAuth1.prototype.buildQueryString=function(obj){var str=[];angular.forEach(obj,function(value,key){str.push(encodeURIComponent(key)+"="+encodeURIComponent(value))});return str.join("&")};OAuth1.$inject=["$http","$window","SatellizerConfig","SatellizerPopup"];return OAuth1}();var OAuth2=function(){function OAuth2($http,$window,$timeout,$q,SatellizerConfig,SatellizerPopup,SatellizerStorage){this.$http=$http;this.$window=$window;this.$timeout=$timeout;this.$q=$q;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.SatellizerStorage=SatellizerStorage;this.defaults={name:null,url:null,clientId:null,authorizationEndpoint:null,redirectUri:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,requiredUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},oauthType:"2.0",popupOptions:{width:null,height:null}}}OAuth2.camelCase=function(name){return name.replace(/([\:\-\_]+(.))/g,function(_,separator,letter,offset){return offset?letter.toUpperCase():letter})};OAuth2.prototype.init=function(options,userData){var _this=this;return this.$q(function(resolve,reject){angular.extend(_this.defaults,options);var stateName=_this.defaults.name+"_state";var _a=_this.defaults,name=_a.name,state=_a.state,popupOptions=_a.popupOptions,redirectUri=_a.redirectUri,responseType=_a.responseType;if(typeof state==="function"){_this.SatellizerStorage.set(stateName,state())}else if(typeof state==="string"){_this.SatellizerStorage.set(stateName,state)}var url=[_this.defaults.authorizationEndpoint,_this.buildQueryString()].join("?");_this.SatellizerPopup.open(url,name,popupOptions,redirectUri).then(function(oauth){if(responseType==="token"||!url){return resolve(oauth)}if(oauth.state&&oauth.state!==_this.SatellizerStorage.get(stateName)){return reject(new Error("The value returned in the state parameter does not match the state value from your original "+"authorization code request."))}resolve(_this.exchangeForToken(oauth,userData))}).catch(function(error){return reject(error)})})};OAuth2.prototype.exchangeForToken=function(oauthData,userData){var _this=this;var payload=angular.extend({},userData);angular.forEach(this.defaults.responseParams,function(value,key){switch(key){case"code":payload[value]=oauthData.code;break;case"clientId":payload[value]=_this.defaults.clientId;break;case"redirectUri":payload[value]=_this.defaults.redirectUri;break;default:payload[value]=oauthData[key]}});if(oauthData.state){payload.state=oauthData.state}var exchangeForTokenUrl=this.SatellizerConfig.baseUrl?joinUrl(this.SatellizerConfig.baseUrl,this.defaults.url):this.defaults.url;return this.$http.post(exchangeForTokenUrl,payload,{withCredentials:this.SatellizerConfig.withCredentials})};OAuth2.prototype.buildQueryString=function(){var _this=this;var keyValuePairs=[];var urlParamsCategories=["defaultUrlParams","requiredUrlParams","optionalUrlParams"];angular.forEach(urlParamsCategories,function(paramsCategory){angular.forEach(_this.defaults[paramsCategory],function(paramName){var camelizedName=OAuth2.camelCase(paramName);var paramValue=angular.isFunction(_this.defaults[paramName])?_this.defaults[paramName]():_this.defaults[camelizedName];if(paramName==="redirect_uri"&&!paramValue){return}if(paramName==="state"){var stateName=_this.defaults.name+"_state";paramValue=encodeURIComponent(_this.SatellizerStorage.get(stateName))}if(paramName==="scope"&&Array.isArray(paramValue)){paramValue=paramValue.join(_this.defaults.scopeDelimiter);if(_this.defaults.scopePrefix){paramValue=[_this.defaults.scopePrefix,paramValue].join(_this.defaults.scopeDelimiter)}}keyValuePairs.push([paramName,paramValue])})});return keyValuePairs.map(function(pair){return pair.join("=")}).join("&")};OAuth2.$inject=["$http","$window","$timeout","$q","SatellizerConfig","SatellizerPopup","SatellizerStorage"];return OAuth2}();var OAuth=function(){function OAuth($http,$window,$timeout,$q,SatellizerConfig,SatellizerPopup,SatellizerStorage,SatellizerShared,SatellizerOAuth1,SatellizerOAuth2){this.$http=$http;this.$window=$window;this.$timeout=$timeout;this.$q=$q;this.SatellizerConfig=SatellizerConfig;this.SatellizerPopup=SatellizerPopup;this.SatellizerStorage=SatellizerStorage;this.SatellizerShared=SatellizerShared;this.SatellizerOAuth1=SatellizerOAuth1;this.SatellizerOAuth2=SatellizerOAuth2}OAuth.prototype.authenticate=function(name,userData){var _this=this;return this.$q(function(resolve,reject){var provider=_this.SatellizerConfig.providers[name];var oauth=null;switch(provider.oauthType){case"1.0":oauth=new OAuth1(_this.$http,_this.$window,_this.SatellizerConfig,_this.SatellizerPopup);break;case"2.0":oauth=new OAuth2(_this.$http,_this.$window,_this.$timeout,_this.$q,_this.SatellizerConfig,_this.SatellizerPopup,_this.SatellizerStorage);break;default:return reject(new Error("Invalid OAuth Type"))}return oauth.init(provider,userData).then(function(response){if(provider.url){_this.SatellizerShared.setToken(response)}resolve(response)}).catch(function(error){reject(error)})})};OAuth.prototype.unlink=function(provider,httpOptions){if(httpOptions===void 0){httpOptions={}}httpOptions.url=httpOptions.url?httpOptions.url:joinUrl(this.SatellizerConfig.baseUrl,this.SatellizerConfig.unlinkUrl);httpOptions.data={provider:provider}||httpOptions.data;httpOptions.method=httpOptions.method||"POST";httpOptions.withCredentials=httpOptions.withCredentials||this.SatellizerConfig.withCredentials;return this.$http(httpOptions)};OAuth.$inject=["$http","$window","$timeout","$q","SatellizerConfig","SatellizerPopup","SatellizerStorage","SatellizerShared","SatellizerOAuth1","SatellizerOAuth2"];return OAuth}();var Storage=function(){function Storage($window,SatellizerConfig){this.$window=$window;this.SatellizerConfig=SatellizerConfig;this.memoryStore={}}Storage.prototype.get=function(key){try{return this.$window[this.SatellizerConfig.storageType].getItem(key)}catch(e){return this.memoryStore[key]}};Storage.prototype.set=function(key,value){try{this.$window[this.SatellizerConfig.storageType].setItem(key,value)}catch(e){this.memoryStore[key]=value}};Storage.prototype.remove=function(key){try{this.$window[this.SatellizerConfig.storageType].removeItem(key)}catch(e){delete this.memoryStore[key]}};Storage.$inject=["$window","SatellizerConfig"];return Storage}();var Interceptor=function(){function Interceptor(SatellizerConfig,SatellizerShared,SatellizerStorage){var _this=this;this.SatellizerConfig=SatellizerConfig;this.SatellizerShared=SatellizerShared;this.SatellizerStorage=SatellizerStorage;this.request=function(config){if(config["skipAuthorization"]){return config}if(_this.SatellizerShared.isAuthenticated()&&_this.SatellizerConfig.httpInterceptor()){var tokenName=_this.SatellizerConfig.tokenPrefix?[_this.SatellizerConfig.tokenPrefix,_this.SatellizerConfig.tokenName].join("_"):_this.SatellizerConfig.tokenName;var token=_this.SatellizerStorage.get(tokenName);if(_this.SatellizerConfig.tokenHeader&&_this.SatellizerConfig.tokenType){token=_this.SatellizerConfig.tokenType+" "+token}config.headers[_this.SatellizerConfig.tokenHeader]=token}return config}}Interceptor.Factory=function(SatellizerConfig,SatellizerShared,SatellizerStorage){return new Interceptor(SatellizerConfig,SatellizerShared,SatellizerStorage)};Interceptor.$inject=["SatellizerConfig","SatellizerShared","SatellizerStorage"];return Interceptor}();Interceptor.Factory.$inject=["SatellizerConfig","SatellizerShared","SatellizerStorage"];var HttpProviderConfig=function(){function HttpProviderConfig($httpProvider){this.$httpProvider=$httpProvider;$httpProvider.interceptors.push(Interceptor.Factory)}HttpProviderConfig.$inject=["$httpProvider"];return HttpProviderConfig}();angular.module("satellizer",[]).provider("$auth",["SatellizerConfig",function(SatellizerConfig){return new AuthProvider(SatellizerConfig)}]).constant("SatellizerConfig",Config.getConstant).service("SatellizerShared",Shared).service("SatellizerLocal",Local).service("SatellizerPopup",Popup).service("SatellizerOAuth",OAuth).service("SatellizerOAuth2",OAuth2).service("SatellizerOAuth1",OAuth1).service("SatellizerStorage",Storage).service("SatellizerInterceptor",Interceptor).config(["$httpProvider",function($httpProvider){return new HttpProviderConfig($httpProvider)}]);var ng1="satellizer";return ng1}); \ No newline at end of file diff --git a/examples/client/app.js b/examples/client/app.js index e32ca674..28f92f51 100644 --- a/examples/client/app.js +++ b/examples/client/app.js @@ -68,7 +68,7 @@ angular.module('MyApp', ['ngResource', 'ngMessages', 'ngAnimate', 'toastr', 'ui. * Satellizer config */ $authProvider.facebook({ - clientId: 'YOUR_FACEBOOK_APP_ID' + clientId: '603122136500203' }); $authProvider.google({ diff --git a/examples/client/vendor/satellizer.js b/examples/client/vendor/satellizer.js index cbeaf257..849500b4 100644 --- a/examples/client/vendor/satellizer.js +++ b/examples/client/vendor/satellizer.js @@ -1,5 +1,5 @@ /** - * Satellizer 0.15.4 + * Satellizer 0.15.5 * (c) 2016 Sahat Yalkabov * License: MIT */ @@ -510,7 +510,6 @@ this.$window = $window; this.$q = $q; this.popup = null; - this.url = 'about:blank'; // TODO remove this.defaults = { redirectUri: null }; @@ -522,8 +521,7 @@ }); return parts.join(','); }; - Popup.prototype.open = function (url, name, popupOptions) { - this.url = url; // TODO remove + Popup.prototype.open = function (url, name, popupOptions, redirectUri, dontPoll) { var width = popupOptions.width || 500; var height = popupOptions.height || 500; var options = this.stringifyOptions({ @@ -533,16 +531,22 @@ left: this.$window.screenX + ((this.$window.outerWidth - width) / 2) }); var popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name; - this.popup = window.open(this.url, popupName, options); + this.popup = this.$window.open(url, popupName, options); if (this.popup && this.popup.focus) { this.popup.focus(); } - // - // if (this.$window['cordova']) { - // return this.eventListener(this.defaults.redirectUri); // TODO pass redirect uri - // } else { - // return this.polling(redirectUri); - // } + if (dontPoll) { + return; + } + if (this.$window['cordova']) { + return this.eventListener(redirectUri); + } + else { + if (url === 'about:blank') { + this.popup.location = url; + } + return this.polling(redirectUri); + } }; Popup.prototype.polling = function (redirectUri) { var _this = this; @@ -587,7 +591,7 @@ var _this = this; return this.$q(function (resolve, reject) { _this.popup.addEventListener('loadstart', function (event) { - if (!event.url.includes(redirectUri)) { + if (event.url.indexOf(redirectUri) !== 0) { return; } var parser = document.createElement('a'); @@ -641,8 +645,11 @@ OAuth1.prototype.init = function (options, userData) { var _this = this; angular.extend(this.defaults, options); + var name = options.name, popupOptions = options.popupOptions; + var redirectUri = this.defaults.redirectUri; + // Should open an empty popup and wait until request token is received if (!this.$window['cordova']) { - this.SatellizerPopup.open('about:blank', options.name, options.popupOptions); + this.SatellizerPopup.open('about:blank', name, popupOptions, redirectUri, true); } return this.getRequestToken().then(function (response) { return _this.openPopup(options, response).then(function (popupResponse) { @@ -651,14 +658,14 @@ }); }; OAuth1.prototype.openPopup = function (options, response) { - var popupUrl = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var url = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var redirectUri = this.defaults.redirectUri; if (this.$window['cordova']) { - this.SatellizerPopup.open(popupUrl, options.name, options.popupOptions); - return this.SatellizerPopup.eventListener(this.defaults.redirectUri); + return this.SatellizerPopup.open(url, options.name, options.popupOptions, redirectUri); } else { - this.SatellizerPopup.popup.location = popupUrl; - return this.SatellizerPopup.polling(this.defaults.redirectUri); + this.SatellizerPopup.popup.location = url; + return this.SatellizerPopup.polling(redirectUri); } }; OAuth1.prototype.getRequestToken = function () { @@ -721,29 +728,25 @@ var _this = this; return this.$q(function (resolve, reject) { angular.extend(_this.defaults, options); - _this.$timeout(function () { - var stateName = _this.defaults.name + '_state'; - var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; - if (typeof state === 'function') { - _this.SatellizerStorage.set(stateName, state()); + var stateName = _this.defaults.name + '_state'; + var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; + if (typeof state === 'function') { + _this.SatellizerStorage.set(stateName, state()); + } + else if (typeof state === 'string') { + _this.SatellizerStorage.set(stateName, state); + } + var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); + _this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then(function (oauth) { + if (responseType === 'token' || !url) { + return resolve(oauth); } - else if (typeof state === 'string') { - _this.SatellizerStorage.set(stateName, state); + if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { + return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.')); } - var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); - _this.SatellizerPopup.open(url, name, popupOptions); - _this.SatellizerPopup.polling(redirectUri).then(function (oauth) { - if (responseType === 'token' || !url) { - return resolve(oauth); - } - if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { - return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + - 'authorization code request.')); - } - resolve(_this.exchangeForToken(oauth, userData)); - }) - .catch(function (error) { return reject(error); }); - }); + resolve(_this.exchangeForToken(oauth, userData)); + }).catch(function (error) { return reject(error); }); }); }; OAuth2.prototype.exchangeForToken = function (oauthData, userData) { diff --git a/examples/ionic/www/lib/satellizer/dist/satellizer.js b/examples/ionic/www/lib/satellizer/dist/satellizer.js new file mode 100755 index 00000000..849500b4 --- /dev/null +++ b/examples/ionic/www/lib/satellizer/dist/satellizer.js @@ -0,0 +1,959 @@ +/** + * Satellizer 0.15.5 + * (c) 2016 Sahat Yalkabov + * License: MIT + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.satellizer = factory()); +}(this, function () { 'use strict'; + + var Config = (function () { + function Config() { + this.baseUrl = '/'; + this.loginUrl = '/auth/login'; + this.signupUrl = '/auth/signup'; + this.unlinkUrl = '/auth/unlink/'; + this.tokenName = 'token'; + this.tokenPrefix = 'satellizer'; + this.tokenHeader = 'Authorization'; + this.tokenType = 'Bearer'; + this.storageType = 'localStorage'; + this.tokenRoot = null; + this.withCredentials = false; + this.providers = { + facebook: { + name: 'facebook', + url: '/auth/facebook', + authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth', + redirectUri: window.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: window.location.origin, + requiredUrlParams: ['scope'], + optionalUrlParams: ['display', 'state'], + scope: ['profile', 'email'], + scopePrefix: 'openid', + scopeDelimiter: ' ', + display: 'popup', + oauthType: '2.0', + popupOptions: { width: 452, height: 633 }, + state: function () { return encodeURIComponent(Math.random().toString(36).substr(2)); } + }, + github: { + name: 'github', + url: '/auth/github', + authorizationEndpoint: 'https://github.com/login/oauth/authorize', + redirectUri: window.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: window.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: window.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: window.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: window.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: window.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: window.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: window.location.origin + '/', + requiredUrlParams: ['scope'], + scope: ['email'], + scopeDelimiter: ' ', + oauthType: '2.0', + popupOptions: { width: 1028, height: 529 } + }, + spotify: { + name: 'spotify', + url: '/auth/spotify', + authorizationEndpoint: 'https://accounts.spotify.com/authorize', + redirectUri: window.location.origin, + optionalUrlParams: ['state'], + requiredUrlParams: ['scope'], + scope: ['user-read-email'], + scopePrefix: '', + scopeDelimiter: ',', + oauthType: '2.0', + popupOptions: { width: 500, height: 530 }, + state: function () { return encodeURIComponent(Math.random().toString(36).substr(2)); } + } + }; + this.httpInterceptor = function () { return true; }; + } + Object.defineProperty(Config, "getConstant", { + get: function () { + return new Config(); + }, + enumerable: true, + configurable: true + }); + return Config; + }()); + ; + + var AuthProvider = (function () { + function AuthProvider(SatellizerConfig) { + this.SatellizerConfig = SatellizerConfig; + } + Object.defineProperty(AuthProvider.prototype, "baseUrl", { + get: function () { return this.SatellizerConfig.baseUrl; }, + set: function (value) { this.SatellizerConfig.baseUrl = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "loginUrl", { + get: function () { return this.SatellizerConfig.loginUrl; }, + set: function (value) { this.SatellizerConfig.loginUrl = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "signupUrl", { + get: function () { return this.SatellizerConfig.signupUrl; }, + set: function (value) { this.SatellizerConfig.signupUrl = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "unlinkUrl", { + get: function () { return this.SatellizerConfig.unlinkUrl; }, + set: function (value) { this.SatellizerConfig.unlinkUrl = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "tokenRoot", { + get: function () { return this.SatellizerConfig.tokenRoot; }, + set: function (value) { this.SatellizerConfig.tokenRoot = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "tokenName", { + get: function () { return this.SatellizerConfig.tokenName; }, + set: function (value) { this.SatellizerConfig.tokenName = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "tokenPrefix", { + get: function () { return this.SatellizerConfig.tokenPrefix; }, + set: function (value) { this.SatellizerConfig.tokenPrefix = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "tokenHeader", { + get: function () { return this.SatellizerConfig.tokenHeader; }, + set: function (value) { this.SatellizerConfig.tokenHeader = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "tokenType", { + get: function () { return this.SatellizerConfig.tokenType; }, + set: function (value) { this.SatellizerConfig.tokenType = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "withCredentials", { + get: function () { return this.SatellizerConfig.withCredentials; }, + set: function (value) { this.SatellizerConfig.withCredentials = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "storageType", { + get: function () { return this.SatellizerConfig.storageType; }, + set: function (value) { this.SatellizerConfig.storageType = value; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(AuthProvider.prototype, "httpInterceptor", { + get: function () { return this.SatellizerConfig.httpInterceptor; }, + set: function (value) { + if (typeof value === 'function') { + this.SatellizerConfig.httpInterceptor = value; + } + else { + this.SatellizerConfig.httpInterceptor = function () { return value; }; + } + }, + enumerable: true, + configurable: true + }); + AuthProvider.prototype.facebook = function (options) { + angular.extend(this.SatellizerConfig.providers.facebook, options); + }; + AuthProvider.prototype.google = function (options) { + angular.extend(this.SatellizerConfig.providers.google, options); + }; + AuthProvider.prototype.github = function (options) { + angular.extend(this.SatellizerConfig.providers.github, options); + }; + AuthProvider.prototype.instagram = function (options) { + angular.extend(this.SatellizerConfig.providers.instagram, options); + }; + AuthProvider.prototype.linkedin = function (options) { + angular.extend(this.SatellizerConfig.providers.linkedin, options); + }; + AuthProvider.prototype.twitter = function (options) { + angular.extend(this.SatellizerConfig.providers.twitter, options); + }; + AuthProvider.prototype.twitch = function (options) { + angular.extend(this.SatellizerConfig.providers.twitch, options); + }; + AuthProvider.prototype.live = function (options) { + angular.extend(this.SatellizerConfig.providers.live, options); + }; + AuthProvider.prototype.yahoo = function (options) { + angular.extend(this.SatellizerConfig.providers.yahoo, options); + }; + AuthProvider.prototype.bitbucket = function (options) { + angular.extend(this.SatellizerConfig.providers.bitbucket, options); + }; + AuthProvider.prototype.spotify = function (options) { + angular.extend(this.SatellizerConfig.providers.spotify, options); + }; + AuthProvider.prototype.oauth1 = function (options) { + this.SatellizerConfig.providers[options.name] = angular.extend(options, { + oauthType: '1.0' + }); + }; + AuthProvider.prototype.oauth2 = function (options) { + this.SatellizerConfig.providers[options.name] = angular.extend(options, { + oauthType: '2.0' + }); + }; + AuthProvider.prototype.$get = function (SatellizerShared, SatellizerLocal, SatellizerOAuth) { + return { + login: function (user, options) { return SatellizerLocal.login(user, options); }, + signup: function (user, options) { return SatellizerLocal.signup(user, options); }, + logout: function () { return SatellizerShared.logout(); }, + authenticate: function (name, data) { return SatellizerOAuth.authenticate(name, data); }, + link: function (name, data) { return SatellizerOAuth.authenticate(name, data); }, + unlink: function (name, options) { return SatellizerOAuth.unlink(name, options); }, + isAuthenticated: function () { return SatellizerShared.isAuthenticated(); }, + getPayload: function () { return SatellizerShared.getPayload(); }, + getToken: function () { return SatellizerShared.getToken(); }, + setToken: function (token) { return SatellizerShared.setToken({ access_token: token }); }, + removeToken: function () { return SatellizerShared.removeToken(); }, + setStorageType: function (type) { return SatellizerShared.setStorageType(type); } + }; + }; + AuthProvider.$inject = ['SatellizerConfig']; + return AuthProvider; + }()); + AuthProvider.prototype.$get.$inject = ['SatellizerShared', 'SatellizerLocal', 'SatellizerOAuth']; + + function joinUrl(baseUrl, url) { + if (/^(?:[a-z]+:)?\/\//i.test(url)) { + return url; + } + var joined = [baseUrl, url].join('/'); + var normalize = function (str) { + return str + .replace(/[\/]+/g, '/') + .replace(/\/\?/g, '?') + .replace(/\/\#/g, '#') + .replace(/\:\//g, '://'); + }; + return normalize(joined); + } + function getFullUrlPath(location) { + var isHttps = location.protocol === 'https:'; + return location.protocol + '//' + location.hostname + + ':' + (location.port || (isHttps ? '443' : '80')) + + (/^\//.test(location.pathname) ? location.pathname : '/' + location.pathname); + } + function parseQueryString(str) { + var obj = {}; + var key; + var value; + angular.forEach((str || '').split('&'), function (keyValue) { + if (keyValue) { + value = keyValue.split('='); + key = decodeURIComponent(value[0]); + obj[key] = angular.isDefined(value[1]) ? decodeURIComponent(value[1]) : true; + } + }); + return obj; + } + function decodeBase64(str) { + var buffer; + if (typeof module !== 'undefined' && module.exports) { + try { + buffer = require('buffer').Buffer; + } + catch (err) { + } + } + var fromCharCode = String.fromCharCode; + var re_btou = new RegExp([ + '[\xC0-\xDF][\x80-\xBF]', + '[\xE0-\xEF][\x80-\xBF]{2}', + '[\xF0-\xF7][\x80-\xBF]{3}' + ].join('|'), 'g'); + var cb_btou = function (cccc) { + switch (cccc.length) { + case 4: + var cp = ((0x07 & cccc.charCodeAt(0)) << 18) + | ((0x3f & cccc.charCodeAt(1)) << 12) + | ((0x3f & cccc.charCodeAt(2)) << 6) + | (0x3f & cccc.charCodeAt(3)); + var offset = cp - 0x10000; + return (fromCharCode((offset >>> 10) + 0xD800) + + fromCharCode((offset & 0x3FF) + 0xDC00)); + case 3: + return fromCharCode(((0x0f & cccc.charCodeAt(0)) << 12) + | ((0x3f & cccc.charCodeAt(1)) << 6) + | (0x3f & cccc.charCodeAt(2))); + default: + return fromCharCode(((0x1f & cccc.charCodeAt(0)) << 6) + | (0x3f & cccc.charCodeAt(1))); + } + }; + var btou = function (b) { + return b.replace(re_btou, cb_btou); + }; + var _decode = buffer ? function (a) { + return (a.constructor === buffer.constructor + ? a : new buffer(a, 'base64')).toString(); + } + : function (a) { + return btou(atob(a)); + }; + return _decode(String(str).replace(/[-_]/g, function (m0) { + return m0 === '-' ? '+' : '/'; + }) + .replace(/[^A-Za-z0-9\+\/]/g, '')); + } + + var Shared = (function () { + function Shared($q, $window, SatellizerConfig, SatellizerStorage) { + this.$q = $q; + this.$window = $window; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerStorage = SatellizerStorage; + var _a = this.SatellizerConfig, tokenName = _a.tokenName, tokenPrefix = _a.tokenPrefix; + this.prefixedTokenName = tokenPrefix ? [tokenPrefix, tokenName].join('_') : tokenName; + } + Shared.prototype.getToken = function () { + return this.SatellizerStorage.get(this.prefixedTokenName); + }; + Shared.prototype.getPayload = function () { + var token = this.SatellizerStorage.get(this.prefixedTokenName); + if (token && token.split('.').length === 3) { + try { + var base64Url = token.split('.')[1]; + var base64 = base64Url.replace('-', '+').replace('_', '/'); + return JSON.parse(decodeBase64(base64)); + } + catch (e) { + } + } + }; + Shared.prototype.setToken = function (response) { + var tokenRoot = this.SatellizerConfig.tokenRoot; + var tokenName = this.SatellizerConfig.tokenName; + var accessToken = response && response.access_token; + var token; + if (accessToken) { + if (angular.isObject(accessToken) && angular.isObject(accessToken.data)) { + response = accessToken; + } + else if (angular.isString(accessToken)) { + token = accessToken; + } + } + if (!token && response) { + var tokenRootData = tokenRoot && tokenRoot.split('.').reduce(function (o, x) { return o[x]; }, response.data); + token = tokenRootData ? tokenRootData[tokenName] : response.data && response.data[tokenName]; + } + if (token) { + this.SatellizerStorage.set(this.prefixedTokenName, token); + } + }; + Shared.prototype.removeToken = function () { + this.SatellizerStorage.remove(this.prefixedTokenName); + }; + Shared.prototype.isAuthenticated = function () { + var token = this.SatellizerStorage.get(this.prefixedTokenName); + if (token) { + if (token.split('.').length === 3) { + try { + var base64Url = token.split('.')[1]; + var base64 = base64Url.replace('-', '+').replace('_', '/'); + var exp = JSON.parse(this.$window.atob(base64)).exp; + if (typeof exp === 'number') { + return Math.round(new Date().getTime() / 1000) < exp; + } + } + catch (e) { + return true; // Pass: Non-JWT token that looks like JWT + } + } + return true; // Pass: All other tokens + } + return false; // Fail: No token at all + }; + Shared.prototype.logout = function () { + this.SatellizerStorage.remove(this.prefixedTokenName); + return this.$q.when(); + }; + Shared.prototype.setStorageType = function (type) { + this.SatellizerConfig.storageType = type; + }; + Shared.$inject = ['$q', '$window', 'SatellizerConfig', 'SatellizerStorage']; + return Shared; + }()); + + var Local = (function () { + function Local($http, SatellizerConfig, SatellizerShared) { + this.$http = $http; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerShared = SatellizerShared; + } + Local.prototype.login = function (user, options) { + var _this = this; + if (options === void 0) { options = {}; } + options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.loginUrl); + options.data = user || options.data; + options.method = options.method || 'POST'; + options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials; + return this.$http(options).then(function (response) { + _this.SatellizerShared.setToken(response); + return response; + }); + }; + Local.prototype.signup = function (user, options) { + if (options === void 0) { options = {}; } + options.url = options.url ? options.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.signupUrl); + options.data = user || options.data; + options.method = options.method || 'POST'; + options.withCredentials = options.withCredentials || this.SatellizerConfig.withCredentials; + return this.$http(options); + }; + Local.$inject = ['$http', 'SatellizerConfig', 'SatellizerShared']; + return Local; + }()); + + var Popup = (function () { + function Popup($interval, $window, $q) { + this.$interval = $interval; + this.$window = $window; + this.$q = $q; + this.popup = null; + this.defaults = { + redirectUri: null + }; + } + Popup.prototype.stringifyOptions = function (options) { + var parts = []; + angular.forEach(options, function (value, key) { + parts.push(key + '=' + value); + }); + return parts.join(','); + }; + Popup.prototype.open = function (url, name, popupOptions, redirectUri, dontPoll) { + var width = popupOptions.width || 500; + var height = popupOptions.height || 500; + var options = this.stringifyOptions({ + width: width, + height: height, + top: this.$window.screenY + ((this.$window.outerHeight - height) / 2.5), + left: this.$window.screenX + ((this.$window.outerWidth - width) / 2) + }); + var popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name; + this.popup = this.$window.open(url, popupName, options); + if (this.popup && this.popup.focus) { + this.popup.focus(); + } + if (dontPoll) { + return; + } + if (this.$window['cordova']) { + return this.eventListener(redirectUri); + } + else { + if (url === 'about:blank') { + this.popup.location = url; + } + return this.polling(redirectUri); + } + }; + Popup.prototype.polling = function (redirectUri) { + var _this = this; + return this.$q(function (resolve, reject) { + var redirectUriParser = document.createElement('a'); + redirectUriParser.href = redirectUri; + var redirectUriPath = getFullUrlPath(redirectUriParser); + var polling = _this.$interval(function () { + if (!_this.popup || _this.popup.closed || _this.popup.closed === undefined) { + _this.$interval.cancel(polling); + reject(new Error('The popup window was closed')); + } + try { + var popupWindowPath = getFullUrlPath(_this.popup.location); + if (popupWindowPath === redirectUriPath) { + if (_this.popup.location.search || _this.popup.location.hash) { + var query = parseQueryString(_this.popup.location.search.substring(1).replace(/\/$/, '')); + var hash = parseQueryString(_this.popup.location.hash.substring(1).replace(/[\/$]/, '')); + var params = angular.extend({}, query, hash); + if (params.error) { + reject(new Error(params.error)); + } + else { + resolve(params); + } + } + else { + reject(new Error('OAuth redirect has occurred but no query or hash parameters were found. ' + + 'They were either not set during the redirect, or were removed—typically by a ' + + 'routing library—before Satellizer could read it.')); + } + _this.$interval.cancel(polling); + _this.popup.close(); + } + } + catch (error) { + } + }, 500); + }); + }; + Popup.prototype.eventListener = function (redirectUri) { + var _this = this; + return this.$q(function (resolve, reject) { + _this.popup.addEventListener('loadstart', function (event) { + if (event.url.indexOf(redirectUri) !== 0) { + return; + } + var parser = document.createElement('a'); + parser.href = event.url; + if (parser.search || parser.hash) { + var query = parseQueryString(parser.search.substring(1).replace(/\/$/, '')); + var hash = parseQueryString(parser.hash.substring(1).replace(/[\/$]/, '')); + var params = angular.extend({}, query, hash); + if (params.error) { + reject(new Error(params.error)); + } + else { + resolve(params); + } + _this.popup.close(); + } + }); + _this.popup.addEventListener('loaderror', function () { + reject(new Error('Authorization failed')); + }); + _this.popup.addEventListener('exit', function () { + reject(new Error('The popup window was closed')); + }); + }); + }; + Popup.$inject = ['$interval', '$window', '$q']; + return Popup; + }()); + + var OAuth1 = (function () { + function OAuth1($http, $window, SatellizerConfig, SatellizerPopup) { + this.$http = $http; + this.$window = $window; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerPopup = SatellizerPopup; + this.defaults = { + name: null, + url: null, + authorizationEndpoint: null, + scope: null, + scopePrefix: null, + scopeDelimiter: null, + redirectUri: null, + requiredUrlParams: null, + defaultUrlParams: null, + oauthType: '1.0', + popupOptions: { width: null, height: null } + }; + } + ; + OAuth1.prototype.init = function (options, userData) { + var _this = this; + angular.extend(this.defaults, options); + var name = options.name, popupOptions = options.popupOptions; + var redirectUri = this.defaults.redirectUri; + // Should open an empty popup and wait until request token is received + if (!this.$window['cordova']) { + this.SatellizerPopup.open('about:blank', name, popupOptions, redirectUri, true); + } + return this.getRequestToken().then(function (response) { + return _this.openPopup(options, response).then(function (popupResponse) { + return _this.exchangeForToken(popupResponse, userData); + }); + }); + }; + OAuth1.prototype.openPopup = function (options, response) { + var url = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var redirectUri = this.defaults.redirectUri; + if (this.$window['cordova']) { + return this.SatellizerPopup.open(url, options.name, options.popupOptions, redirectUri); + } + else { + this.SatellizerPopup.popup.location = url; + return this.SatellizerPopup.polling(redirectUri); + } + }; + OAuth1.prototype.getRequestToken = function () { + var url = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url; + return this.$http.post(url, this.defaults); + }; + OAuth1.prototype.exchangeForToken = function (oauthData, userData) { + var payload = angular.extend({}, userData, oauthData); + var exchangeForTokenUrl = this.SatellizerConfig.baseUrl ? joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : this.defaults.url; + return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials }); + }; + OAuth1.prototype.buildQueryString = function (obj) { + var str = []; + angular.forEach(obj, function (value, key) { + str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + }); + return str.join('&'); + }; + OAuth1.$inject = ['$http', '$window', 'SatellizerConfig', 'SatellizerPopup']; + return OAuth1; + }()); + + var OAuth2 = (function () { + function OAuth2($http, $window, $timeout, $q, SatellizerConfig, SatellizerPopup, SatellizerStorage) { + this.$http = $http; + this.$window = $window; + this.$timeout = $timeout; + this.$q = $q; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerPopup = SatellizerPopup; + this.SatellizerStorage = SatellizerStorage; + this.defaults = { + name: null, + url: null, + clientId: null, + authorizationEndpoint: null, + redirectUri: null, + scope: null, + scopePrefix: null, + scopeDelimiter: null, + state: null, + requiredUrlParams: null, + defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'], + responseType: 'code', + responseParams: { + code: 'code', + clientId: 'clientId', + redirectUri: 'redirectUri' + }, + oauthType: '2.0', + popupOptions: { width: null, height: null } + }; + } + OAuth2.camelCase = function (name) { + return name.replace(/([\:\-\_]+(.))/g, function (_, separator, letter, offset) { + return offset ? letter.toUpperCase() : letter; + }); + }; + OAuth2.prototype.init = function (options, userData) { + var _this = this; + return this.$q(function (resolve, reject) { + angular.extend(_this.defaults, options); + var stateName = _this.defaults.name + '_state'; + var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; + if (typeof state === 'function') { + _this.SatellizerStorage.set(stateName, state()); + } + else if (typeof state === 'string') { + _this.SatellizerStorage.set(stateName, state); + } + var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); + _this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then(function (oauth) { + if (responseType === 'token' || !url) { + return resolve(oauth); + } + if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { + return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.')); + } + resolve(_this.exchangeForToken(oauth, userData)); + }).catch(function (error) { return reject(error); }); + }); + }; + OAuth2.prototype.exchangeForToken = function (oauthData, userData) { + var _this = this; + var payload = angular.extend({}, userData); + angular.forEach(this.defaults.responseParams, function (value, key) { + switch (key) { + case 'code': + payload[value] = oauthData.code; + break; + case 'clientId': + payload[value] = _this.defaults.clientId; + break; + case 'redirectUri': + payload[value] = _this.defaults.redirectUri; + break; + default: + payload[value] = oauthData[key]; + } + }); + if (oauthData.state) { + payload.state = oauthData.state; + } + var exchangeForTokenUrl = this.SatellizerConfig.baseUrl ? + joinUrl(this.SatellizerConfig.baseUrl, this.defaults.url) : + this.defaults.url; + return this.$http.post(exchangeForTokenUrl, payload, { withCredentials: this.SatellizerConfig.withCredentials }); + }; + OAuth2.prototype.buildQueryString = function () { + var _this = this; + var keyValuePairs = []; + var urlParamsCategories = ['defaultUrlParams', 'requiredUrlParams', 'optionalUrlParams']; + angular.forEach(urlParamsCategories, function (paramsCategory) { + angular.forEach(_this.defaults[paramsCategory], function (paramName) { + var camelizedName = OAuth2.camelCase(paramName); + var paramValue = angular.isFunction(_this.defaults[paramName]) ? _this.defaults[paramName]() : _this.defaults[camelizedName]; + if (paramName === 'redirect_uri' && !paramValue) { + return; + } + if (paramName === 'state') { + var stateName = _this.defaults.name + '_state'; + paramValue = encodeURIComponent(_this.SatellizerStorage.get(stateName)); + } + if (paramName === 'scope' && Array.isArray(paramValue)) { + paramValue = paramValue.join(_this.defaults.scopeDelimiter); + if (_this.defaults.scopePrefix) { + paramValue = [_this.defaults.scopePrefix, paramValue].join(_this.defaults.scopeDelimiter); + } + } + keyValuePairs.push([paramName, paramValue]); + }); + }); + return keyValuePairs.map(function (pair) { return pair.join('='); }).join('&'); + }; + OAuth2.$inject = ['$http', '$window', '$timeout', '$q', 'SatellizerConfig', 'SatellizerPopup', 'SatellizerStorage']; + return OAuth2; + }()); + + var OAuth = (function () { + function OAuth($http, $window, $timeout, $q, SatellizerConfig, SatellizerPopup, SatellizerStorage, SatellizerShared, SatellizerOAuth1, SatellizerOAuth2) { + this.$http = $http; + this.$window = $window; + this.$timeout = $timeout; + this.$q = $q; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerPopup = SatellizerPopup; + this.SatellizerStorage = SatellizerStorage; + this.SatellizerShared = SatellizerShared; + this.SatellizerOAuth1 = SatellizerOAuth1; + this.SatellizerOAuth2 = SatellizerOAuth2; + } + OAuth.prototype.authenticate = function (name, userData) { + var _this = this; + return this.$q(function (resolve, reject) { + var provider = _this.SatellizerConfig.providers[name]; + var oauth = null; + switch (provider.oauthType) { + case '1.0': + oauth = new OAuth1(_this.$http, _this.$window, _this.SatellizerConfig, _this.SatellizerPopup); + break; + case '2.0': + oauth = new OAuth2(_this.$http, _this.$window, _this.$timeout, _this.$q, _this.SatellizerConfig, _this.SatellizerPopup, _this.SatellizerStorage); + break; + default: + return reject(new Error('Invalid OAuth Type')); + } + return oauth.init(provider, userData).then(function (response) { + if (provider.url) { + _this.SatellizerShared.setToken(response); + } + resolve(response); + }).catch(function (error) { + reject(error); + }); + }); + }; + OAuth.prototype.unlink = function (provider, httpOptions) { + if (httpOptions === void 0) { httpOptions = {}; } + httpOptions.url = httpOptions.url ? httpOptions.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.unlinkUrl); + httpOptions.data = { provider: provider } || httpOptions.data; + httpOptions.method = httpOptions.method || 'POST'; + httpOptions.withCredentials = httpOptions.withCredentials || this.SatellizerConfig.withCredentials; + return this.$http(httpOptions); + }; + OAuth.$inject = [ + '$http', + '$window', + '$timeout', + '$q', + 'SatellizerConfig', + 'SatellizerPopup', + 'SatellizerStorage', + 'SatellizerShared', + 'SatellizerOAuth1', + 'SatellizerOAuth2' + ]; + return OAuth; + }()); + + var Storage = (function () { + function Storage($window, SatellizerConfig) { + this.$window = $window; + this.SatellizerConfig = SatellizerConfig; + this.memoryStore = {}; + } + Storage.prototype.get = function (key) { + try { + return this.$window[this.SatellizerConfig.storageType].getItem(key); + } + catch (e) { + return this.memoryStore[key]; + } + }; + Storage.prototype.set = function (key, value) { + try { + this.$window[this.SatellizerConfig.storageType].setItem(key, value); + } + catch (e) { + this.memoryStore[key] = value; + } + }; + Storage.prototype.remove = function (key) { + try { + this.$window[this.SatellizerConfig.storageType].removeItem(key); + } + catch (e) { + delete this.memoryStore[key]; + } + }; + Storage.$inject = ['$window', 'SatellizerConfig']; + return Storage; + }()); + + var Interceptor = (function () { + function Interceptor(SatellizerConfig, SatellizerShared, SatellizerStorage) { + var _this = this; + this.SatellizerConfig = SatellizerConfig; + this.SatellizerShared = SatellizerShared; + this.SatellizerStorage = SatellizerStorage; + this.request = function (config) { + if (config['skipAuthorization']) { + return config; + } + if (_this.SatellizerShared.isAuthenticated() && _this.SatellizerConfig.httpInterceptor()) { + var tokenName = _this.SatellizerConfig.tokenPrefix ? + [_this.SatellizerConfig.tokenPrefix, _this.SatellizerConfig.tokenName].join('_') : _this.SatellizerConfig.tokenName; + var token = _this.SatellizerStorage.get(tokenName); + if (_this.SatellizerConfig.tokenHeader && _this.SatellizerConfig.tokenType) { + token = _this.SatellizerConfig.tokenType + ' ' + token; + } + config.headers[_this.SatellizerConfig.tokenHeader] = token; + } + return config; + }; + } + Interceptor.Factory = function (SatellizerConfig, SatellizerShared, SatellizerStorage) { + return new Interceptor(SatellizerConfig, SatellizerShared, SatellizerStorage); + }; + Interceptor.$inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage']; + return Interceptor; + }()); + Interceptor.Factory.$inject = ['SatellizerConfig', 'SatellizerShared', 'SatellizerStorage']; + + var HttpProviderConfig = (function () { + function HttpProviderConfig($httpProvider) { + this.$httpProvider = $httpProvider; + $httpProvider.interceptors.push(Interceptor.Factory); + } + HttpProviderConfig.$inject = ['$httpProvider']; + return HttpProviderConfig; + }()); + + angular.module('satellizer', []) + .provider('$auth', ['SatellizerConfig', function (SatellizerConfig) { return new AuthProvider(SatellizerConfig); }]) + .constant('SatellizerConfig', Config.getConstant) + .service('SatellizerShared', Shared) + .service('SatellizerLocal', Local) + .service('SatellizerPopup', Popup) + .service('SatellizerOAuth', OAuth) + .service('SatellizerOAuth2', OAuth2) + .service('SatellizerOAuth1', OAuth1) + .service('SatellizerStorage', Storage) + .service('SatellizerInterceptor', Interceptor) + .config(['$httpProvider', function ($httpProvider) { return new HttpProviderConfig($httpProvider); }]); + var ng1 = 'satellizer'; + + return ng1; + +})); +//# sourceMappingURL=satellizer.js.map diff --git a/examples/ionic/www/lib/satellizer/satellizer.js b/examples/ionic/www/lib/satellizer/satellizer.js new file mode 100755 index 00000000..2c4c36b6 --- /dev/null +++ b/examples/ionic/www/lib/satellizer/satellizer.js @@ -0,0 +1,969 @@ +/** + * Satellizer 0.14.1 + * (c) 2016 Sahat Yalkabov + * License: MIT + */ + +// CommonJS package manager support. +if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) { + module.exports = 'satellizer'; +} + +(function(window, angular, undefined) { + 'use strict'; + + if (!window.location.origin) { + window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : ''); + } + + angular.module('satellizer', []) + .constant('SatellizerConfig', { + httpInterceptor: function() { return true; }, + withCredentials: false, + tokenRoot: null, + 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: window.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: window.location.origin, + requiredUrlParams: ['scope'], + optionalUrlParams: ['display', 'state'], + scope: ['profile', 'email'], + scopePrefix: 'openid', + scopeDelimiter: ' ', + display: 'popup', + oauthType: '2.0', + popupOptions: { width: 452, height: 633 }, + state: function() { + var rand = Math.random().toString(36).substr(2); + return encodeURIComponent(rand); + } + }, + github: { + name: 'github', + url: '/auth/github', + authorizationEndpoint: 'https://github.com/login/oauth/authorize', + redirectUri: window.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: window.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: window.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: window.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: window.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: window.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: window.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: window.location.origin + '/', + requiredUrlParams: ['scope'], + scope: ['email'], + scopeDelimiter: ' ', + oauthType: '2.0', + popupOptions: { width: 1028, height: 529 } + } + } + }) + .provider('$auth', ['SatellizerConfig', function(config) { + Object.defineProperties(this, { + httpInterceptor: { + get: function() { return config.httpInterceptor; }, + set: function(value) { + if (typeof value === 'function') { + config.httpInterceptor = value; + } else { + config.httpInterceptor = function() { + return value; + }; + } + } + }, + baseUrl: { + get: function() { return config.baseUrl; }, + set: function(value) { config.baseUrl = value; } + }, + loginUrl: { + get: function() { return config.loginUrl; }, + set: function(value) { config.loginUrl = value; } + }, + signupUrl: { + get: function() { return config.signupUrl; }, + set: function(value) { config.signupUrl = value; } + }, + tokenRoot: { + get: function() { return config.tokenRoot; }, + set: function(value) { config.tokenRoot = value; } + }, + tokenName: { + get: function() { return config.tokenName; }, + set: function(value) { config.tokenName = value; } + }, + tokenPrefix: { + get: function() { return config.tokenPrefix; }, + set: function(value) { config.tokenPrefix = value; } + }, + unlinkUrl: { + get: function() { return config.unlinkUrl; }, + set: function(value) { config.unlinkUrl = value; } + }, + authHeader: { + get: function() { return config.authHeader; }, + set: function(value) { config.authHeader = value; } + }, + authToken: { + get: function() { return config.authToken; }, + set: function(value) { config.authToken = value; } + }, + withCredentials: { + get: function() { return config.withCredentials; }, + set: function(value) { config.withCredentials = value; } + }, + storageType: { + get: function() { return config.storageType; }, + set: function(value) { config.storageType = value; } + } + }); + + angular.forEach(Object.keys(config.providers), function(provider) { + this[provider] = function(params) { + return angular.extend(config.providers[provider], params); + }; + }, this); + + var oauth = function(params) { + config.providers[params.name] = config.providers[params.name] || {}; + angular.extend(config.providers[params.name], params); + }; + + this.oauth1 = function(params) { + oauth(params); + config.providers[params.name].oauthType = '1.0'; + }; + + this.oauth2 = function(params) { + oauth(params); + config.providers[params.name].oauthType = '2.0'; + }; + + this.$get = [ + '$q', + 'SatellizerShared', + 'SatellizerLocal', + 'SatellizerOauth', + function($q, shared, local, oauth) { + var $auth = {}; + + $auth.login = function(user, opts) { + return local.login(user, opts); + }; + + $auth.signup = function(user, options) { + return local.signup(user, options); + }; + + $auth.logout = function() { + return shared.logout(); + }; + + $auth.authenticate = function(name, userData) { + return oauth.authenticate(name, userData); + }; + + $auth.link = function(name, userData) { + return oauth.authenticate(name, userData); + }; + + $auth.unlink = function(provider, opts) { + return oauth.unlink(provider, opts); + }; + + $auth.isAuthenticated = function() { + return shared.isAuthenticated(); + }; + + $auth.getToken = function() { + return shared.getToken(); + }; + + $auth.setToken = function(token) { + shared.setToken({ access_token: token }); + }; + + $auth.removeToken = function() { + return shared.removeToken(); + }; + + $auth.getPayload = function() { + return shared.getPayload(); + }; + + $auth.setStorageType = function(type) { + return shared.setStorageType(type); + }; + + return $auth; + }]; + }]) + .factory('SatellizerShared', [ + '$q', + '$window', + '$log', + 'SatellizerConfig', + 'SatellizerStorage', + function($q, $window, $log, config, storage) { + var Shared = {}; + + var tokenName = config.tokenPrefix ? [config.tokenPrefix, config.tokenName].join('_') : config.tokenName; + + Shared.getToken = function() { + return storage.get(tokenName); + }; + + Shared.getPayload = function() { + var token = storage.get(tokenName); + + if (token && token.split('.').length === 3) { + try { + var base64Url = token.split('.')[1]; + var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); + return JSON.parse(decodeURIComponent(escape(window.atob(base64)))); + } catch(e) { + return undefined; + } + } + }; + + Shared.setToken = function(response) { + if (!response) { + return $log.warn('Can\'t set token without passing a value'); + } + + var accessToken = response && response.access_token; + var token; + + if (accessToken) { + if (angular.isObject(accessToken) && angular.isObject(accessToken.data)) { + response = accessToken; + } else if (angular.isString(accessToken)) { + token = accessToken; + } + } + + if (!token && response) { + var tokenRootData = config.tokenRoot && config.tokenRoot.split('.').reduce(function(o, x) { return o[x]; }, response.data); + token = tokenRootData ? tokenRootData[config.tokenName] : response.data && response.data[config.tokenName]; + } + + if (!token) { + var tokenPath = config.tokenRoot ? config.tokenRoot + '.' + config.tokenName : config.tokenName; + return $log.warn('Expecting a token named "' + tokenPath); + } + + storage.set(tokenName, token); + }; + + Shared.removeToken = function() { + storage.remove(tokenName); + }; + + /** + * @returns {boolean} + */ + Shared.isAuthenticated = function() { + var token = storage.get(tokenName); + // A token is present + if (token) { + // Token with a valid JWT format XXX.YYY.ZZZ + if (token.split('.').length === 3) { + // Could be a valid JWT or an access token with the same format + try { + var base64Url = token.split('.')[1]; + var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); + var exp = JSON.parse($window.atob(base64)).exp; + // JWT with an optonal expiration claims + if (exp) { + var isExpired = Math.round(new Date().getTime() / 1000) >= exp; + if (isExpired) { + // FAIL: Expired token + return false; + } else { + // PASS: Non-expired token + return true; + } + } + } catch(e) { + // PASS: Non-JWT token that looks like JWT + return true; + } + } + // PASS: All other tokens + return true; + } + // FAIL: No token at all + return false; + }; + + Shared.logout = function() { + storage.remove(tokenName); + return $q.when(); + }; + + Shared.setStorageType = function(type) { + config.storageType = type; + }; + + return Shared; + }]) + .factory('SatellizerOauth', [ + '$q', + '$http', + 'SatellizerConfig', + 'SatellizerUtils', + 'SatellizerShared', + 'SatellizerOauth1', + 'SatellizerOauth2', + function($q, $http, config, utils, shared, Oauth1, Oauth2) { + var Oauth = {}; + + Oauth.authenticate = function(name, userData) { + var provider = config.providers[name].oauthType === '1.0' ? new Oauth1() : new Oauth2(); + var deferred = $q.defer(); + + provider.open(config.providers[name], userData || {}) + .then(function(response) { + // This is for a scenario when someone wishes to opt out from + // Satellizer's magic by doing authorization code exchange and + // saving a token manually. + if (config.providers[name].url) { + shared.setToken(response, false); + } + deferred.resolve(response); + }) + .catch(function(error) { + deferred.reject(error); + }); + + return deferred.promise; + }; + + Oauth.unlink = function(provider, opts) { + opts = opts || {}; + opts.url = opts.url ? opts.url : utils.joinUrl(config.baseUrl, config.unlinkUrl); + opts.data = { provider: provider } || opts.data; + opts.method = opts.method || 'POST'; + opts.withCredentials = opts.withCredentials || config.withCredentials; + + return $http(opts); + }; + + return Oauth; + }]) + .factory('SatellizerLocal', [ + '$http', + 'SatellizerUtils', + 'SatellizerShared', + 'SatellizerConfig', + function($http, utils, shared, config) { + var Local = {}; + + Local.login = function(user, opts) { + opts = opts || {}; + opts.url = opts.url ? opts.url : utils.joinUrl(config.baseUrl, config.loginUrl); + opts.data = user || opts.data; + opts.method = opts.method || 'POST'; + opts.withCredentials = opts.withCredentials || config.withCredentials; + + return $http(opts).then(function(response) { + shared.setToken(response); + return response; + }); + }; + + Local.signup = function(user, opts) { + opts = opts || {}; + opts.url = opts.url ? opts.url : utils.joinUrl(config.baseUrl, config.signupUrl); + opts.data = user || opts.data; + opts.method = opts.method || 'POST'; + opts.withCredentials = opts.withCredentials || config.withCredentials; + + return $http(opts); + }; + + return Local; + }]) + .factory('SatellizerOauth2', [ + '$q', + '$http', + '$window', + '$timeout', + 'SatellizerPopup', + 'SatellizerUtils', + 'SatellizerConfig', + 'SatellizerStorage', + function($q, $http, $window, $timeout, popup, utils, config, storage) { + return function() { + var Oauth2 = {}; + + var defaults = { + defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'], + responseType: 'code', + responseParams: { + code: 'code', + clientId: 'clientId', + redirectUri: 'redirectUri' + } + }; + + Oauth2.open = function(options, userData) { + defaults = utils.merge(options, defaults); + var defer = $q.defer(); + + $timeout(function () { + var url; + var openPopup; + var stateName = defaults.name + '_state'; + + if (angular.isFunction(defaults.state)) { + storage.set(stateName, defaults.state()); + } else if (angular.isString(defaults.state)) { + storage.set(stateName, defaults.state); + } + + url = [defaults.authorizationEndpoint, Oauth2.buildQueryString()].join('?'); + + if (window.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(defaults.redirectUri); + } + + openPopup + .then(function(oauthData) { + // When no server URL provided, return popup params as-is. + // This is for a scenario when someone wishes to opt out from + // Satellizer's magic by doing authorization code exchange and + // saving a token manually. + if (defaults.responseType === 'token' || !defaults.url) { + return defer.resolve(oauthData); + } + + if (oauthData.state && oauthData.state !== storage.get(stateName)) { + return defer.reject( + 'The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.' + ); + } + + defer.resolve(Oauth2.exchangeForToken(oauthData, userData)); + }, function (err) { + defer.reject(err); + }); + }); + + return defer.promise; + }; + + Oauth2.exchangeForToken = function(oauthData, userData) { + var data = angular.extend({}, userData); + + angular.forEach(defaults.responseParams, function(value, key) { + switch (key) { + case 'code': + data[value] = oauthData.code; + break; + case 'clientId': + data[value] = defaults.clientId; + break; + case 'redirectUri': + data[value] = defaults.redirectUri; + break; + default: + data[value] = oauthData[key]; + } + }); + + if (oauthData.state) { + data.state = oauthData.state; + } + + var exchangeForTokenUrl = config.baseUrl ? utils.joinUrl(config.baseUrl, defaults.url) : defaults.url; + + return $http.post(exchangeForTokenUrl, data, { withCredentials: config.withCredentials }); + }; + + Oauth2.buildQueryString = function() { + var keyValuePairs = []; + var urlParamsCategories = ['defaultUrlParams', 'requiredUrlParams', 'optionalUrlParams']; + + angular.forEach(urlParamsCategories, function(paramsCategory) { + angular.forEach(defaults[paramsCategory], function(paramName) { + var camelizedName = utils.camelCase(paramName); + var paramValue = angular.isFunction(defaults[paramName]) ? defaults[paramName]() : defaults[camelizedName]; + + if (paramName === 'redirect_uri' && !paramValue) { + return; + } + + if (paramName === 'state') { + var stateName = defaults.name + '_state'; + paramValue = encodeURIComponent(storage.get(stateName)); + } + + if (paramName === 'scope' && Array.isArray(paramValue)) { + paramValue = paramValue.join(defaults.scopeDelimiter); + + if (defaults.scopePrefix) { + paramValue = [defaults.scopePrefix, paramValue].join(defaults.scopeDelimiter); + } + } + + keyValuePairs.push([paramName, paramValue]); + }); + }); + + return keyValuePairs.map(function(pair) { + return pair.join('='); + }).join('&'); + }; + + return Oauth2; + }; + }]) + .factory('SatellizerOauth1', [ + '$q', + '$http', + 'SatellizerPopup', + 'SatellizerConfig', + 'SatellizerUtils', + function($q, $http, popup, config, utils) { + return function() { + var Oauth1 = {}; + + var defaults = { + url: null, + name: null, + popupOptions: null, + redirectUri: null, + authorizationEndpoint: null + }; + + Oauth1.open = function(options, userData) { + angular.extend(defaults, options); + var popupWindow; + var serverUrl = config.baseUrl ? utils.joinUrl(config.baseUrl, defaults.url) : defaults.url; + + if (!window.cordova) { + popupWindow = popup.open('', defaults.name, defaults.popupOptions, defaults.redirectUri); + } + + return $http.post(serverUrl, defaults) + .then(function(response) { + var url = [defaults.authorizationEndpoint, Oauth1.buildQueryString(response.data)].join('?'); + + if (window.cordova) { + popupWindow = popup.open(url, defaults.name, defaults.popupOptions, defaults.redirectUri); + } else { + popupWindow.popupWindow.location = url; + } + + var popupListener; + + if (window.cordova) { + popupListener = popupWindow.eventListener(defaults.redirectUri); + } else { + popupListener = popupWindow.pollPopup(defaults.redirectUri); + } + + return popupListener + .then(function(response) { + return Oauth1.exchangeForToken(response, userData); + }); + }); + + }; + + Oauth1.exchangeForToken = function(oauthData, userData) { + var data = angular.extend({}, userData, oauthData); + var exchangeForTokenUrl = config.baseUrl ? utils.joinUrl(config.baseUrl, defaults.url) : defaults.url; + return $http.post(exchangeForTokenUrl, data, { withCredentials: config.withCredentials }); + }; + + Oauth1.buildQueryString = function(obj) { + var str = []; + + angular.forEach(obj, function(value, key) { + str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + }); + + return str.join('&'); + }; + + return Oauth1; + }; + }]) + .factory('SatellizerPopup', [ + '$q', + '$interval', + '$window', + 'SatellizerConfig', + 'SatellizerUtils', + function($q, $interval, $window, config, utils) { + var Popup = {}; + + Popup.url = ''; + Popup.popupWindow = null; + + Popup.open = function(url, name, options) { + Popup.url = url; + + var stringifiedOptions = Popup.stringifyOptions(Popup.prepareOptions(options)); + var UA = $window.navigator.userAgent; + var windowName = (window.cordova || UA.indexOf('CriOS') > -1) ? '_blank' : name; + + Popup.popupWindow = $window.open(url, windowName, stringifiedOptions); + + $window.popup = Popup.popupWindow; + + if (Popup.popupWindow && Popup.popupWindow.focus) { + Popup.popupWindow.focus(); + } + + return Popup; + }; + + Popup.eventListener = function(redirectUri) { + var deferred = $q.defer(); + + Popup.popupWindow.addEventListener('loadstart', function(event) { + if (event.url.indexOf(redirectUri) !== 0) { + return; + } + + var parser = document.createElement('a'); + parser.href = event.url; + + if (parser.search || parser.hash) { + var queryParams = parser.search.substring(1).replace(/\/$/, ''); + var hashParams = parser.hash.substring(1).replace(/\/$/, ''); + var hash = utils.parseQueryString(hashParams); + var qs = utils.parseQueryString(queryParams); + + angular.extend(qs, hash); + + if (!qs.error) { + deferred.resolve(qs); + } + + Popup.popupWindow.close(); + } + }); + + Popup.popupWindow.addEventListener('loaderror', function() { + deferred.reject('Authorization Failed'); + }); + + return deferred.promise; + }; + + Popup.pollPopup = function(redirectUri) { + var deferred = $q.defer(); + + var redirectUriParser = document.createElement('a'); + redirectUriParser.href = redirectUri; + + var redirectUriPath = utils.getFullUrlPath(redirectUriParser); + + var polling = $interval(function() { + if (!Popup.popupWindow || Popup.popupWindow.closed || Popup.popupWindow.closed === undefined) { + deferred.reject('The popup window was closed.'); + $interval.cancel(polling); + } + + try { + var popupWindowPath = utils.getFullUrlPath(Popup.popupWindow.location); + + // Redirect has occurred. + if (popupWindowPath === redirectUriPath) { + // Contains query/hash parameters as expected. + if (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); + var qs = utils.parseQueryString(queryParams); + + angular.extend(qs, hash); + + if (qs.error) { + deferred.reject(qs); + } else { + deferred.resolve(qs); + } + } else { + // Does not contain query/hash parameters, can't do anything at this point. + deferred.reject( + 'Redirect has occurred but no query or hash parameters were found. ' + + 'They were either not set during the redirect, or were removed before Satellizer ' + + 'could read them, e.g. AngularJS routing mechanism.' + ); + } + + $interval.cancel(polling); + Popup.popupWindow.close(); + } + } 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. + } + }, 20); + + return deferred.promise; + }; + + Popup.prepareOptions = function(options) { + options = options || {}; + var width = options.width || 500; + var height = options.height || 500; + + return angular.extend({ + width: width, + height: height, + left: $window.screenX + (($window.outerWidth - width) / 2), + top: $window.screenY + (($window.outerHeight - height) / 2.5) + }, options); + }; + + Popup.stringifyOptions = function(options) { + var parts = []; + angular.forEach(options, function(value, key) { + parts.push(key + '=' + value); + }); + return parts.join(','); + }; + + return Popup; + }]) + .service('SatellizerUtils', function() { + this.getFullUrlPath = function(location) { + var isHttps = location.protocol === 'https:'; + return location.protocol + '//' + location.hostname + + ':' + (location.port || (isHttps ? '443' : '80')) + + (/^\//.test(location.pathname) ? location.pathname : '/' + location.pathname); + }; + + this.camelCase = function(name) { + return name.replace(/([\:\-\_]+(.))/g, function(_, separator, letter, offset) { + return offset ? letter.toUpperCase() : letter; + }); + }; + + this.parseQueryString = function(keyValue) { + var obj = {}, key, value; + angular.forEach((keyValue || '').split('&'), function(keyValue) { + if (keyValue) { + value = keyValue.split('='); + key = decodeURIComponent(value[0]); + obj[key] = angular.isDefined(value[1]) ? decodeURIComponent(value[1]) : true; + } + }); + return obj; + }; + + this.joinUrl = function(baseUrl, url) { + if (/^(?:[a-z]+:)?\/\//i.test(url)) { + return url; + } + + var joined = [baseUrl, url].join('/'); + + var normalize = function(str) { + return str + .replace(/[\/]+/g, '/') + .replace(/\/\?/g, '?') + .replace(/\/\#/g, '#') + .replace(/\:\//g, '://'); + }; + + return normalize(joined); + }; + + this.merge = function(obj1, obj2) { + var result = {}; + for (var i in obj1) { + if (obj1.hasOwnProperty(i)) { + if ((i in obj2) && (typeof obj1[i] === 'object') && (i !== null)) { + result[i] = this.merge(obj1[i], obj2[i]); + } else { + result[i] = obj1[i]; + } + } + } + for (i in obj2) { + if (obj2.hasOwnProperty(i)) { + if (i in result) { + continue; + } + result[i] = obj2[i]; + } + + } + return result; + }; + }) + .factory('SatellizerStorage', ['$window', '$log', 'SatellizerConfig', function($window, $log, config) { + + var store = {}; + + // Check if localStorage or sessionStorage is available or enabled + var isStorageAvailable = (function() { + try { + var supported = config.storageType in $window && $window[config.storageType] !== null; + + if (supported) { + var key = Math.random().toString(36).substring(7); + $window[config.storageType].setItem(key, ''); + $window[config.storageType].removeItem(key); + } + + return supported; + } catch (e) { + return false; + } + })(); + + if (!isStorageAvailable) { + $log.warn(config.storageType + ' is not available.'); + } + + return { + get: function(key) { + return isStorageAvailable ? $window[config.storageType].getItem(key) : store[key]; + }, + set: function(key, value) { + return isStorageAvailable ? $window[config.storageType].setItem(key, value) : store[key] = value; + }, + remove: function(key) { + return isStorageAvailable ? $window[config.storageType].removeItem(key): delete store[key]; + } + }; + + }]) + .factory('SatellizerInterceptor', [ + '$q', + 'SatellizerConfig', + 'SatellizerStorage', + 'SatellizerShared', + function($q, config, storage, shared) { + return { + request: function(request) { + if (request.skipAuthorization) { + return request; + } + + if (shared.isAuthenticated() && config.httpInterceptor(request)) { + var tokenName = config.tokenPrefix ? config.tokenPrefix + '_' + config.tokenName : config.tokenName; + var token = storage.get(tokenName); + + if (config.authHeader && config.authToken) { + token = config.authToken + ' ' + token; + } + + request.headers[config.authHeader] = token; + } + + return request; + }, + responseError: function(response) { + return $q.reject(response); + } + }; + }]) + .config(['$httpProvider', function($httpProvider) { + $httpProvider.interceptors.push('SatellizerInterceptor'); + }]); + +})(window, window.angular); diff --git a/examples/server/node/config.js b/examples/server/node/config.js index 078c9a74..709374a4 100644 --- a/examples/server/node/config.js +++ b/examples/server/node/config.js @@ -4,7 +4,7 @@ module.exports = { TOKEN_SECRET: process.env.TOKEN_SECRET || 'YOUR_UNIQUE_JWT_TOKEN_SECRET', // OAuth 2.0 - FACEBOOK_SECRET: process.env.FACEBOOK_SECRET || 'YOUR_FACEBOOK_CLIENT_SECRET', + FACEBOOK_SECRET: process.env.FACEBOOK_SECRET || '84e952da26fc9e7a12bbc32523efa8a0', FOURSQUARE_SECRET: process.env.FOURSQUARE_SECRET || 'YOUR_FOURSQUARE_CLIENT_SECRET', GOOGLE_SECRET: process.env.GOOGLE_SECRET || 'YOUR_GOOGLE_CLIENT_SECRET', GITHUB_SECRET: process.env.GITHUB_SECRET || 'YOUR_GITHUB_CLIENT_SECRET', @@ -17,6 +17,6 @@ module.exports = { SPOTIFY_SECRET: process.env.SPOTIFY_SECRET || 'YOUR_SPOTIFY_CLIENT_SECRET', // OAuth 1.0 - TWITTER_KEY: process.env.TWITTER_KEY || 'YOUR_TWITTER_CONSUMER_KEY', - TWITTER_SECRET: process.env.TWITTER_SECRET || 'YOUR_TWITTER_CONSUMER_SECRET' + TWITTER_KEY: process.env.TWITTER_KEY || 'vdrg4sqxyTPSRdJHKu4UVVdeD', + TWITTER_SECRET: process.env.TWITTER_SECRET || 'cUIobhRgRlXsFyObUMg3tBq56EgGSwabmcavQP4fncABvotRMA' }; diff --git a/examples/server/php/public/app.js b/examples/server/php/public/app.js index e32ca674..28f92f51 100644 --- a/examples/server/php/public/app.js +++ b/examples/server/php/public/app.js @@ -68,7 +68,7 @@ angular.module('MyApp', ['ngResource', 'ngMessages', 'ngAnimate', 'toastr', 'ui. * Satellizer config */ $authProvider.facebook({ - clientId: 'YOUR_FACEBOOK_APP_ID' + clientId: '603122136500203' }); $authProvider.google({ diff --git a/examples/server/php/public/vendor/satellizer.js b/examples/server/php/public/vendor/satellizer.js index cbeaf257..849500b4 100644 --- a/examples/server/php/public/vendor/satellizer.js +++ b/examples/server/php/public/vendor/satellizer.js @@ -1,5 +1,5 @@ /** - * Satellizer 0.15.4 + * Satellizer 0.15.5 * (c) 2016 Sahat Yalkabov * License: MIT */ @@ -510,7 +510,6 @@ this.$window = $window; this.$q = $q; this.popup = null; - this.url = 'about:blank'; // TODO remove this.defaults = { redirectUri: null }; @@ -522,8 +521,7 @@ }); return parts.join(','); }; - Popup.prototype.open = function (url, name, popupOptions) { - this.url = url; // TODO remove + Popup.prototype.open = function (url, name, popupOptions, redirectUri, dontPoll) { var width = popupOptions.width || 500; var height = popupOptions.height || 500; var options = this.stringifyOptions({ @@ -533,16 +531,22 @@ left: this.$window.screenX + ((this.$window.outerWidth - width) / 2) }); var popupName = this.$window['cordova'] || this.$window.navigator.userAgent.indexOf('CriOS') > -1 ? '_blank' : name; - this.popup = window.open(this.url, popupName, options); + this.popup = this.$window.open(url, popupName, options); if (this.popup && this.popup.focus) { this.popup.focus(); } - // - // if (this.$window['cordova']) { - // return this.eventListener(this.defaults.redirectUri); // TODO pass redirect uri - // } else { - // return this.polling(redirectUri); - // } + if (dontPoll) { + return; + } + if (this.$window['cordova']) { + return this.eventListener(redirectUri); + } + else { + if (url === 'about:blank') { + this.popup.location = url; + } + return this.polling(redirectUri); + } }; Popup.prototype.polling = function (redirectUri) { var _this = this; @@ -587,7 +591,7 @@ var _this = this; return this.$q(function (resolve, reject) { _this.popup.addEventListener('loadstart', function (event) { - if (!event.url.includes(redirectUri)) { + if (event.url.indexOf(redirectUri) !== 0) { return; } var parser = document.createElement('a'); @@ -641,8 +645,11 @@ OAuth1.prototype.init = function (options, userData) { var _this = this; angular.extend(this.defaults, options); + var name = options.name, popupOptions = options.popupOptions; + var redirectUri = this.defaults.redirectUri; + // Should open an empty popup and wait until request token is received if (!this.$window['cordova']) { - this.SatellizerPopup.open('about:blank', options.name, options.popupOptions); + this.SatellizerPopup.open('about:blank', name, popupOptions, redirectUri, true); } return this.getRequestToken().then(function (response) { return _this.openPopup(options, response).then(function (popupResponse) { @@ -651,14 +658,14 @@ }); }; OAuth1.prototype.openPopup = function (options, response) { - var popupUrl = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var url = [options.authorizationEndpoint, this.buildQueryString(response.data)].join('?'); + var redirectUri = this.defaults.redirectUri; if (this.$window['cordova']) { - this.SatellizerPopup.open(popupUrl, options.name, options.popupOptions); - return this.SatellizerPopup.eventListener(this.defaults.redirectUri); + return this.SatellizerPopup.open(url, options.name, options.popupOptions, redirectUri); } else { - this.SatellizerPopup.popup.location = popupUrl; - return this.SatellizerPopup.polling(this.defaults.redirectUri); + this.SatellizerPopup.popup.location = url; + return this.SatellizerPopup.polling(redirectUri); } }; OAuth1.prototype.getRequestToken = function () { @@ -721,29 +728,25 @@ var _this = this; return this.$q(function (resolve, reject) { angular.extend(_this.defaults, options); - _this.$timeout(function () { - var stateName = _this.defaults.name + '_state'; - var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; - if (typeof state === 'function') { - _this.SatellizerStorage.set(stateName, state()); + var stateName = _this.defaults.name + '_state'; + var _a = _this.defaults, name = _a.name, state = _a.state, popupOptions = _a.popupOptions, redirectUri = _a.redirectUri, responseType = _a.responseType; + if (typeof state === 'function') { + _this.SatellizerStorage.set(stateName, state()); + } + else if (typeof state === 'string') { + _this.SatellizerStorage.set(stateName, state); + } + var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); + _this.SatellizerPopup.open(url, name, popupOptions, redirectUri).then(function (oauth) { + if (responseType === 'token' || !url) { + return resolve(oauth); } - else if (typeof state === 'string') { - _this.SatellizerStorage.set(stateName, state); + if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { + return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + + 'authorization code request.')); } - var url = [_this.defaults.authorizationEndpoint, _this.buildQueryString()].join('?'); - _this.SatellizerPopup.open(url, name, popupOptions); - _this.SatellizerPopup.polling(redirectUri).then(function (oauth) { - if (responseType === 'token' || !url) { - return resolve(oauth); - } - if (oauth.state && oauth.state !== _this.SatellizerStorage.get(stateName)) { - return reject(new Error('The value returned in the state parameter does not match the state value from your original ' + - 'authorization code request.')); - } - resolve(_this.exchangeForToken(oauth, userData)); - }) - .catch(function (error) { return reject(error); }); - }); + resolve(_this.exchangeForToken(oauth, userData)); + }).catch(function (error) { return reject(error); }); }); }; OAuth2.prototype.exchangeForToken = function (oauthData, userData) { diff --git a/package.json b/package.json index 92b9f90a..7d451c69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "satellizer", "description": "Token-based AngularJS Authentication", - "version": "0.15.4", + "version": "0.15.5", "main": "dist/satellizer.js", "scripts": { "start": "supervisor ./examples/server/node/server.js",