Skip to content

Commit

Permalink
Merge branch 'release/1.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrubelic committed Oct 24, 2017
2 parents 4034466 + c8e7de9 commit 3ddeb22
Show file tree
Hide file tree
Showing 16 changed files with 620 additions and 172 deletions.
152 changes: 121 additions & 31 deletions dist/vue-authenticate.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-authenticate v1.3.2
* vue-authenticate v1.3.3
* https://github.com/dgrubelic/vue-authenticate
* Released under the MIT License.
*/
Expand Down Expand Up @@ -39,7 +39,9 @@ function camelCase(name) {
});
}


function isUndefined(value) {
return typeof value === 'undefined'
}



Expand Down Expand Up @@ -213,6 +215,47 @@ function decodeBase64(str) {
);
}

function parseCookies(str) {
if (str.length === 0) { return {}; }
var parsed = {};
var pattern = new RegExp('\\s*;\\s*');
str.split(pattern).forEach(function (i) {
var ref = i.split('=');
var encodedKey = ref[0];
var encodedValue = ref[1];
var key = decodeURIComponent(encodedKey);
var value = decodeURIComponent(encodedValue);
parsed[key] = value;
});
return parsed;
}

function formatOptions(options) {
var path = options.path;
var domain = options.domain;
var expires = options.expires;
var secure = options.secure;
return [
typeof path === 'undefined' || path === null
? '' : ';path=' + path,
typeof domain === 'undefined' || domain === null
? '' : ';domain=' + domain,
typeof expires === 'undefined' || expires === null
? '' : ';expires=' + expires.toUTCString(),
typeof secure === 'undefined' || secure === null || secure === false
? '' : ';secure'
].join('');
}

function formatCookie(key, value, options) {
return [
encodeURIComponent(key),
'=',
encodeURIComponent(value),
formatOptions(options)
].join('');
}

// Store setTimeout reference so promise-polyfill will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var setTimeoutFunc = setTimeout;
Expand Down Expand Up @@ -451,23 +494,28 @@ var defaultOptions = {
logoutUrl: null,
storageType: 'localStorage',
storageNamespace: 'vue-authenticate',
cookieStorage: {
domain: window.location.hostname,
path: '/',
secure: false
},
requestDataKey: 'data',
responseDataKey: 'data',

/**
* Default request interceptor for Axios library
* @context {VueAuthenticate}
*/
bindRequestInterceptor: function () {
var this$1 = this;
bindRequestInterceptor: function ($auth) {
var tokenHeader = $auth.options.tokenHeader;

this.$http.interceptors.request.use(function (config) {
if (this$1.isAuthenticated()) {
config.headers['Authorization'] = [
this$1.options.tokenType, this$1.getToken()
$auth.$http.interceptors.request.use(function (config) {
if ($auth.isAuthenticated()) {
config.headers[tokenHeader] = [
$auth.options.tokenType, $auth.getToken()
].join(' ');
} else {
delete config.headers['Authorization'];
delete config.headers[tokenHeader];
}
return config
});
Expand All @@ -477,11 +525,9 @@ var defaultOptions = {
* Default response interceptor for Axios library
* @contect {VueAuthenticate}
*/
bindResponseInterceptor: function () {
var this$1 = this;

this.$http.interceptors.response.use(function (response) {
this$1.setToken(response);
bindResponseInterceptor: function ($auth) {
$auth.$http.interceptors.response.use(function (response) {
$auth.setToken(response);
return response
});
},
Expand All @@ -491,7 +537,7 @@ var defaultOptions = {
name: 'facebook',
url: '/auth/facebook',
authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',
redirectUri: null,
redirectUri: window.location.origin + '/',
requiredUrlParams: ['display', 'scope'],
scope: ['email'],
scopeDelimiter: ',',
Expand All @@ -504,7 +550,7 @@ var defaultOptions = {
name: 'google',
url: '/auth/google',
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
redirectUri: null,
redirectUri: window.location.origin,
requiredUrlParams: ['scope'],
optionalUrlParams: ['display'],
scope: ['profile', 'email'],
Expand All @@ -519,7 +565,7 @@ var defaultOptions = {
name: 'github',
url: '/auth/github',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
redirectUri: null,
redirectUri: window.location.origin,
optionalUrlParams: ['scope'],
scope: ['user:email'],
scopeDelimiter: ' ',
Expand All @@ -531,18 +577,19 @@ var defaultOptions = {
name: 'instagram',
url: '/auth/instagram',
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
redirectUri: null,
redirectUri: window.location.origin,
requiredUrlParams: ['scope'],
scope: ['basic'],
scopeDelimiter: '+',
oauthType: '2.0'
oauthType: '2.0',
popupOptions: { width: null, height: null }
},

twitter: {
name: 'twitter',
url: '/auth/twitter',
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
redirectUri: null,
redirectUri: window.location.origin,
oauthType: '1.0',
popupOptions: { width: 495, height: 645 }
},
Expand All @@ -551,7 +598,7 @@ var defaultOptions = {
name: 'bitbucket',
url: '/auth/bitbucket',
authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',
redirectUri: null,
redirectUri: window.location.origin + '/',
optionalUrlParams: ['scope'],
scope: ['email'],
scopeDelimiter: ' ',
Expand All @@ -563,7 +610,7 @@ var defaultOptions = {
name: 'linkedin',
url: '/auth/linkedin',
authorizationEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: null,
redirectUri: window.location.origin,
requiredUrlParams: ['state'],
scope: ['r_emailaddress'],
scopeDelimiter: ' ',
Expand All @@ -576,7 +623,7 @@ var defaultOptions = {
name: 'live',
url: '/auth/live',
authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',
redirectUri: null,
redirectUri: window.location.origin,
requiredUrlParams: ['display', 'scope'],
scope: ['wl.emails'],
scopeDelimiter: ' ',
Expand All @@ -589,7 +636,7 @@ var defaultOptions = {
name: null,
url: '/auth/oauth1',
authorizationEndpoint: null,
redirectUri: null,
redirectUri: window.location.origin,
oauthType: '1.0',
popupOptions: null
},
Expand All @@ -598,7 +645,7 @@ var defaultOptions = {
name: null,
url: '/auth/oauth2',
clientId: null,
redirectUri: null,
redirectUri: window.location.origin,
authorizationEndpoint: null,
defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],
requiredUrlParams: null,
Expand All @@ -619,6 +666,46 @@ var defaultOptions = {
}
};

var CookieStorage = function CookieStorage(defaultOptions) {
this._defaultOptions = objectExtend({
domain: window.location.hostname,
expires: null,
path: '/',
secure: false
}, defaultOptions);
};

CookieStorage.prototype.setItem = function setItem (key, value) {
var options = objectExtend({}, this._defaultOptions);
var cookie = formatCookie(key, value, options);
this._setCookie(cookie);
};

CookieStorage.prototype.getItem = function getItem (key) {
var cookies = parseCookies(this._getCookie());
return cookies.hasOwnProperty(key) ? cookies[key] : null;
};

CookieStorage.prototype.removeItem = function removeItem (key) {
var value = '';
var defaultOptions = objectExtend({}, this._defaultOptions);
var options = objectExtend(defaultOptions, {
expires: new Date(0)
});
var cookie = formatCookie(key, value, options);
this._setCookie(cookie);
};

CookieStorage.prototype._getCookie = function _getCookie () {
return typeof document === 'undefined'
? '' : typeof document.cookie === 'undefined'
? '' : document.cookie;
};

CookieStorage.prototype._setCookie = function _setCookie (cookie) {
document.cookie = cookie;
};

var LocalStorage = function LocalStorage(namespace) {
this.namespace = namespace || null;
};
Expand Down Expand Up @@ -703,7 +790,10 @@ function StorageFactory(options) {
window.sessionStorage.setItem('testKey', 'test');
window.sessionStorage.removeItem('testKey');
return new LocalStorage$2(options.storageNamespace)
} catch(e) {}
} catch (e) {}

case 'cookieStorage':
return new CookieStorage(options.cookieStorage);

case 'memoryStorage':
default:
Expand Down Expand Up @@ -793,7 +883,9 @@ OAuthPopup.prototype._stringifyOptions = function _stringifyOptions () {

var options = [];
for (var optionKey in this$1.popupOptions) {
options.push((optionKey + "=" + (this$1.popupOptions[optionKey])));
if (!isUndefined(this$1.popupOptions[optionKey])) {
options.push((optionKey + "=" + (this$1.popupOptions[optionKey])));
}
}
return options.join(',')
};
Expand All @@ -809,7 +901,7 @@ var defaultProviderConfig = {
requiredUrlParams: null,
defaultUrlParams: null,
oauthType: '1.0',
popupOptions: { width: null, height: null }
popupOptions: {}
};

var OAuth = function OAuth($http, storage, providerConfig, options) {
Expand Down Expand Up @@ -928,7 +1020,7 @@ var defaultProviderConfig$1 = {
redirectUri: 'redirectUri'
},
oauthType: '2.0',
popupOptions: { width: null, height: null }
popupOptions: {}
};

var OAuth2 = function OAuth2($http, storage, providerConfig, options) {
Expand Down Expand Up @@ -1289,8 +1381,6 @@ VueAuthenticate.prototype.authenticate = function authenticate (provider, userDa
} else {
return reject(new Error('Authentication failed'))
}
}).catch(function () {
reject(new Error('Authentication error occurred'));
})
})
};
Expand Down
Loading

0 comments on commit 3ddeb22

Please sign in to comment.