11/*!
2- * vue-authenticate v1.3.2
2+ * vue-authenticate v1.3.3
33 * https://github.com/dgrubelic/vue-authenticate
44 * Released under the MIT License.
55 */
@@ -39,7 +39,9 @@ function camelCase(name) {
3939 } ) ;
4040}
4141
42-
42+ function isUndefined ( value ) {
43+ return typeof value === 'undefined'
44+ }
4345
4446
4547
@@ -213,6 +215,47 @@ function decodeBase64(str) {
213215 ) ;
214216}
215217
218+ function parseCookies ( str ) {
219+ if ( str . length === 0 ) { return { } ; }
220+ var parsed = { } ;
221+ var pattern = new RegExp ( '\\s*;\\s*' ) ;
222+ str . split ( pattern ) . forEach ( function ( i ) {
223+ var ref = i . split ( '=' ) ;
224+ var encodedKey = ref [ 0 ] ;
225+ var encodedValue = ref [ 1 ] ;
226+ var key = decodeURIComponent ( encodedKey ) ;
227+ var value = decodeURIComponent ( encodedValue ) ;
228+ parsed [ key ] = value ;
229+ } ) ;
230+ return parsed ;
231+ }
232+
233+ function formatOptions ( options ) {
234+ var path = options . path ;
235+ var domain = options . domain ;
236+ var expires = options . expires ;
237+ var secure = options . secure ;
238+ return [
239+ typeof path === 'undefined' || path === null
240+ ? '' : ';path=' + path ,
241+ typeof domain === 'undefined' || domain === null
242+ ? '' : ';domain=' + domain ,
243+ typeof expires === 'undefined' || expires === null
244+ ? '' : ';expires=' + expires . toUTCString ( ) ,
245+ typeof secure === 'undefined' || secure === null || secure === false
246+ ? '' : ';secure'
247+ ] . join ( '' ) ;
248+ }
249+
250+ function formatCookie ( key , value , options ) {
251+ return [
252+ encodeURIComponent ( key ) ,
253+ '=' ,
254+ encodeURIComponent ( value ) ,
255+ formatOptions ( options )
256+ ] . join ( '' ) ;
257+ }
258+
216259// Store setTimeout reference so promise-polyfill will be unaffected by
217260// other code modifying setTimeout (like sinon.useFakeTimers())
218261var setTimeoutFunc = setTimeout ;
@@ -451,23 +494,28 @@ var defaultOptions = {
451494 logoutUrl : null ,
452495 storageType : 'localStorage' ,
453496 storageNamespace : 'vue-authenticate' ,
497+ cookieStorage : {
498+ domain : window . location . hostname ,
499+ path : '/' ,
500+ secure : false
501+ } ,
454502 requestDataKey : 'data' ,
455503 responseDataKey : 'data' ,
456504
457505 /**
458506 * Default request interceptor for Axios library
459507 * @context {VueAuthenticate}
460508 */
461- bindRequestInterceptor : function ( ) {
462- var this$1 = this ;
509+ bindRequestInterceptor : function ( $auth ) {
510+ var tokenHeader = $auth . options . tokenHeader ;
463511
464- this . $http . interceptors . request . use ( function ( config ) {
465- if ( this$1 . isAuthenticated ( ) ) {
466- config . headers [ 'Authorization' ] = [
467- this$1 . options . tokenType , this$1 . getToken ( )
512+ $auth . $http . interceptors . request . use ( function ( config ) {
513+ if ( $auth . isAuthenticated ( ) ) {
514+ config . headers [ tokenHeader ] = [
515+ $auth . options . tokenType , $auth . getToken ( )
468516 ] . join ( ' ' ) ;
469517 } else {
470- delete config . headers [ 'Authorization' ] ;
518+ delete config . headers [ tokenHeader ] ;
471519 }
472520 return config
473521 } ) ;
@@ -477,11 +525,9 @@ var defaultOptions = {
477525 * Default response interceptor for Axios library
478526 * @contect {VueAuthenticate}
479527 */
480- bindResponseInterceptor : function ( ) {
481- var this$1 = this ;
482-
483- this . $http . interceptors . response . use ( function ( response ) {
484- this$1 . setToken ( response ) ;
528+ bindResponseInterceptor : function ( $auth ) {
529+ $auth . $http . interceptors . response . use ( function ( response ) {
530+ $auth . setToken ( response ) ;
485531 return response
486532 } ) ;
487533 } ,
@@ -491,7 +537,7 @@ var defaultOptions = {
491537 name : 'facebook' ,
492538 url : '/auth/facebook' ,
493539 authorizationEndpoint : 'https://www.facebook.com/v2.5/dialog/oauth' ,
494- redirectUri : null ,
540+ redirectUri : window . location . origin + '/' ,
495541 requiredUrlParams : [ 'display' , 'scope' ] ,
496542 scope : [ 'email' ] ,
497543 scopeDelimiter : ',' ,
@@ -504,7 +550,7 @@ var defaultOptions = {
504550 name : 'google' ,
505551 url : '/auth/google' ,
506552 authorizationEndpoint : 'https://accounts.google.com/o/oauth2/auth' ,
507- redirectUri : null ,
553+ redirectUri : window . location . origin ,
508554 requiredUrlParams : [ 'scope' ] ,
509555 optionalUrlParams : [ 'display' ] ,
510556 scope : [ 'profile' , 'email' ] ,
@@ -519,7 +565,7 @@ var defaultOptions = {
519565 name : 'github' ,
520566 url : '/auth/github' ,
521567 authorizationEndpoint : 'https://github.com/login/oauth/authorize' ,
522- redirectUri : null ,
568+ redirectUri : window . location . origin ,
523569 optionalUrlParams : [ 'scope' ] ,
524570 scope : [ 'user:email' ] ,
525571 scopeDelimiter : ' ' ,
@@ -531,18 +577,19 @@ var defaultOptions = {
531577 name : 'instagram' ,
532578 url : '/auth/instagram' ,
533579 authorizationEndpoint : 'https://api.instagram.com/oauth/authorize' ,
534- redirectUri : null ,
580+ redirectUri : window . location . origin ,
535581 requiredUrlParams : [ 'scope' ] ,
536582 scope : [ 'basic' ] ,
537583 scopeDelimiter : '+' ,
538- oauthType : '2.0'
584+ oauthType : '2.0' ,
585+ popupOptions : { width : null , height : null }
539586 } ,
540587
541588 twitter : {
542589 name : 'twitter' ,
543590 url : '/auth/twitter' ,
544591 authorizationEndpoint : 'https://api.twitter.com/oauth/authenticate' ,
545- redirectUri : null ,
592+ redirectUri : window . location . origin ,
546593 oauthType : '1.0' ,
547594 popupOptions : { width : 495 , height : 645 }
548595 } ,
@@ -551,7 +598,7 @@ var defaultOptions = {
551598 name : 'bitbucket' ,
552599 url : '/auth/bitbucket' ,
553600 authorizationEndpoint : 'https://bitbucket.org/site/oauth2/authorize' ,
554- redirectUri : null ,
601+ redirectUri : window . location . origin + '/' ,
555602 optionalUrlParams : [ 'scope' ] ,
556603 scope : [ 'email' ] ,
557604 scopeDelimiter : ' ' ,
@@ -563,7 +610,7 @@ var defaultOptions = {
563610 name : 'linkedin' ,
564611 url : '/auth/linkedin' ,
565612 authorizationEndpoint : 'https://www.linkedin.com/oauth/v2/authorization' ,
566- redirectUri : null ,
613+ redirectUri : window . location . origin ,
567614 requiredUrlParams : [ 'state' ] ,
568615 scope : [ 'r_emailaddress' ] ,
569616 scopeDelimiter : ' ' ,
@@ -576,7 +623,7 @@ var defaultOptions = {
576623 name : 'live' ,
577624 url : '/auth/live' ,
578625 authorizationEndpoint : 'https://login.live.com/oauth20_authorize.srf' ,
579- redirectUri : null ,
626+ redirectUri : window . location . origin ,
580627 requiredUrlParams : [ 'display' , 'scope' ] ,
581628 scope : [ 'wl.emails' ] ,
582629 scopeDelimiter : ' ' ,
@@ -589,7 +636,7 @@ var defaultOptions = {
589636 name : null ,
590637 url : '/auth/oauth1' ,
591638 authorizationEndpoint : null ,
592- redirectUri : null ,
639+ redirectUri : window . location . origin ,
593640 oauthType : '1.0' ,
594641 popupOptions : null
595642 } ,
@@ -598,7 +645,7 @@ var defaultOptions = {
598645 name : null ,
599646 url : '/auth/oauth2' ,
600647 clientId : null ,
601- redirectUri : null ,
648+ redirectUri : window . location . origin ,
602649 authorizationEndpoint : null ,
603650 defaultUrlParams : [ 'response_type' , 'client_id' , 'redirect_uri' ] ,
604651 requiredUrlParams : null ,
@@ -619,6 +666,46 @@ var defaultOptions = {
619666 }
620667} ;
621668
669+ var CookieStorage = function CookieStorage ( defaultOptions ) {
670+ this . _defaultOptions = objectExtend ( {
671+ domain : window . location . hostname ,
672+ expires : null ,
673+ path : '/' ,
674+ secure : false
675+ } , defaultOptions ) ;
676+ } ;
677+
678+ CookieStorage . prototype . setItem = function setItem ( key , value ) {
679+ var options = objectExtend ( { } , this . _defaultOptions ) ;
680+ var cookie = formatCookie ( key , value , options ) ;
681+ this . _setCookie ( cookie ) ;
682+ } ;
683+
684+ CookieStorage . prototype . getItem = function getItem ( key ) {
685+ var cookies = parseCookies ( this . _getCookie ( ) ) ;
686+ return cookies . hasOwnProperty ( key ) ? cookies [ key ] : null ;
687+ } ;
688+
689+ CookieStorage . prototype . removeItem = function removeItem ( key ) {
690+ var value = '' ;
691+ var defaultOptions = objectExtend ( { } , this . _defaultOptions ) ;
692+ var options = objectExtend ( defaultOptions , {
693+ expires : new Date ( 0 )
694+ } ) ;
695+ var cookie = formatCookie ( key , value , options ) ;
696+ this . _setCookie ( cookie ) ;
697+ } ;
698+
699+ CookieStorage . prototype . _getCookie = function _getCookie ( ) {
700+ return typeof document === 'undefined'
701+ ? '' : typeof document . cookie === 'undefined'
702+ ? '' : document . cookie ;
703+ } ;
704+
705+ CookieStorage . prototype . _setCookie = function _setCookie ( cookie ) {
706+ document . cookie = cookie ;
707+ } ;
708+
622709var LocalStorage = function LocalStorage ( namespace ) {
623710 this . namespace = namespace || null ;
624711} ;
@@ -703,7 +790,10 @@ function StorageFactory(options) {
703790 window . sessionStorage . setItem ( 'testKey' , 'test' ) ;
704791 window . sessionStorage . removeItem ( 'testKey' ) ;
705792 return new LocalStorage$2 ( options . storageNamespace )
706- } catch ( e ) { }
793+ } catch ( e ) { }
794+
795+ case 'cookieStorage' :
796+ return new CookieStorage ( options . cookieStorage ) ;
707797
708798 case 'memoryStorage' :
709799 default :
@@ -793,7 +883,9 @@ OAuthPopup.prototype._stringifyOptions = function _stringifyOptions () {
793883
794884 var options = [ ] ;
795885 for ( var optionKey in this$1 . popupOptions ) {
796- options . push ( ( optionKey + "=" + ( this$1 . popupOptions [ optionKey ] ) ) ) ;
886+ if ( ! isUndefined ( this$1 . popupOptions [ optionKey ] ) ) {
887+ options . push ( ( optionKey + "=" + ( this$1 . popupOptions [ optionKey ] ) ) ) ;
888+ }
797889 }
798890 return options . join ( ',' )
799891} ;
@@ -809,7 +901,7 @@ var defaultProviderConfig = {
809901 requiredUrlParams : null ,
810902 defaultUrlParams : null ,
811903 oauthType : '1.0' ,
812- popupOptions : { width : null , height : null }
904+ popupOptions : { }
813905} ;
814906
815907var OAuth = function OAuth ( $http , storage , providerConfig , options ) {
@@ -928,7 +1020,7 @@ var defaultProviderConfig$1 = {
9281020 redirectUri : 'redirectUri'
9291021 } ,
9301022 oauthType : '2.0' ,
931- popupOptions : { width : null , height : null }
1023+ popupOptions : { }
9321024} ;
9331025
9341026var OAuth2 = function OAuth2 ( $http , storage , providerConfig , options ) {
@@ -1289,8 +1381,6 @@ VueAuthenticate.prototype.authenticate = function authenticate (provider, userDa
12891381 } else {
12901382 return reject ( new Error ( 'Authentication failed' ) )
12911383 }
1292- } ) . catch ( function ( ) {
1293- reject ( new Error ( 'Authentication error occurred' ) ) ;
12941384 } )
12951385 } )
12961386} ;
0 commit comments