1
1
/*!
2
- * vue-authenticate v1.3.2
2
+ * vue-authenticate v1.3.3
3
3
* https://github.com/dgrubelic/vue-authenticate
4
4
* Released under the MIT License.
5
5
*/
@@ -39,7 +39,9 @@ function camelCase(name) {
39
39
} ) ;
40
40
}
41
41
42
-
42
+ function isUndefined ( value ) {
43
+ return typeof value === 'undefined'
44
+ }
43
45
44
46
45
47
@@ -213,6 +215,47 @@ function decodeBase64(str) {
213
215
) ;
214
216
}
215
217
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
+
216
259
// Store setTimeout reference so promise-polyfill will be unaffected by
217
260
// other code modifying setTimeout (like sinon.useFakeTimers())
218
261
var setTimeoutFunc = setTimeout ;
@@ -451,23 +494,28 @@ var defaultOptions = {
451
494
logoutUrl : null ,
452
495
storageType : 'localStorage' ,
453
496
storageNamespace : 'vue-authenticate' ,
497
+ cookieStorage : {
498
+ domain : window . location . hostname ,
499
+ path : '/' ,
500
+ secure : false
501
+ } ,
454
502
requestDataKey : 'data' ,
455
503
responseDataKey : 'data' ,
456
504
457
505
/**
458
506
* Default request interceptor for Axios library
459
507
* @context {VueAuthenticate}
460
508
*/
461
- bindRequestInterceptor : function ( ) {
462
- var this$1 = this ;
509
+ bindRequestInterceptor : function ( $auth ) {
510
+ var tokenHeader = $auth . options . tokenHeader ;
463
511
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 ( )
468
516
] . join ( ' ' ) ;
469
517
} else {
470
- delete config . headers [ 'Authorization' ] ;
518
+ delete config . headers [ tokenHeader ] ;
471
519
}
472
520
return config
473
521
} ) ;
@@ -477,11 +525,9 @@ var defaultOptions = {
477
525
* Default response interceptor for Axios library
478
526
* @contect {VueAuthenticate}
479
527
*/
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 ) ;
485
531
return response
486
532
} ) ;
487
533
} ,
@@ -491,7 +537,7 @@ var defaultOptions = {
491
537
name : 'facebook' ,
492
538
url : '/auth/facebook' ,
493
539
authorizationEndpoint : 'https://www.facebook.com/v2.5/dialog/oauth' ,
494
- redirectUri : null ,
540
+ redirectUri : window . location . origin + '/' ,
495
541
requiredUrlParams : [ 'display' , 'scope' ] ,
496
542
scope : [ 'email' ] ,
497
543
scopeDelimiter : ',' ,
@@ -504,7 +550,7 @@ var defaultOptions = {
504
550
name : 'google' ,
505
551
url : '/auth/google' ,
506
552
authorizationEndpoint : 'https://accounts.google.com/o/oauth2/auth' ,
507
- redirectUri : null ,
553
+ redirectUri : window . location . origin ,
508
554
requiredUrlParams : [ 'scope' ] ,
509
555
optionalUrlParams : [ 'display' ] ,
510
556
scope : [ 'profile' , 'email' ] ,
@@ -519,7 +565,7 @@ var defaultOptions = {
519
565
name : 'github' ,
520
566
url : '/auth/github' ,
521
567
authorizationEndpoint : 'https://github.com/login/oauth/authorize' ,
522
- redirectUri : null ,
568
+ redirectUri : window . location . origin ,
523
569
optionalUrlParams : [ 'scope' ] ,
524
570
scope : [ 'user:email' ] ,
525
571
scopeDelimiter : ' ' ,
@@ -531,18 +577,19 @@ var defaultOptions = {
531
577
name : 'instagram' ,
532
578
url : '/auth/instagram' ,
533
579
authorizationEndpoint : 'https://api.instagram.com/oauth/authorize' ,
534
- redirectUri : null ,
580
+ redirectUri : window . location . origin ,
535
581
requiredUrlParams : [ 'scope' ] ,
536
582
scope : [ 'basic' ] ,
537
583
scopeDelimiter : '+' ,
538
- oauthType : '2.0'
584
+ oauthType : '2.0' ,
585
+ popupOptions : { width : null , height : null }
539
586
} ,
540
587
541
588
twitter : {
542
589
name : 'twitter' ,
543
590
url : '/auth/twitter' ,
544
591
authorizationEndpoint : 'https://api.twitter.com/oauth/authenticate' ,
545
- redirectUri : null ,
592
+ redirectUri : window . location . origin ,
546
593
oauthType : '1.0' ,
547
594
popupOptions : { width : 495 , height : 645 }
548
595
} ,
@@ -551,7 +598,7 @@ var defaultOptions = {
551
598
name : 'bitbucket' ,
552
599
url : '/auth/bitbucket' ,
553
600
authorizationEndpoint : 'https://bitbucket.org/site/oauth2/authorize' ,
554
- redirectUri : null ,
601
+ redirectUri : window . location . origin + '/' ,
555
602
optionalUrlParams : [ 'scope' ] ,
556
603
scope : [ 'email' ] ,
557
604
scopeDelimiter : ' ' ,
@@ -563,7 +610,7 @@ var defaultOptions = {
563
610
name : 'linkedin' ,
564
611
url : '/auth/linkedin' ,
565
612
authorizationEndpoint : 'https://www.linkedin.com/oauth/v2/authorization' ,
566
- redirectUri : null ,
613
+ redirectUri : window . location . origin ,
567
614
requiredUrlParams : [ 'state' ] ,
568
615
scope : [ 'r_emailaddress' ] ,
569
616
scopeDelimiter : ' ' ,
@@ -576,7 +623,7 @@ var defaultOptions = {
576
623
name : 'live' ,
577
624
url : '/auth/live' ,
578
625
authorizationEndpoint : 'https://login.live.com/oauth20_authorize.srf' ,
579
- redirectUri : null ,
626
+ redirectUri : window . location . origin ,
580
627
requiredUrlParams : [ 'display' , 'scope' ] ,
581
628
scope : [ 'wl.emails' ] ,
582
629
scopeDelimiter : ' ' ,
@@ -589,7 +636,7 @@ var defaultOptions = {
589
636
name : null ,
590
637
url : '/auth/oauth1' ,
591
638
authorizationEndpoint : null ,
592
- redirectUri : null ,
639
+ redirectUri : window . location . origin ,
593
640
oauthType : '1.0' ,
594
641
popupOptions : null
595
642
} ,
@@ -598,7 +645,7 @@ var defaultOptions = {
598
645
name : null ,
599
646
url : '/auth/oauth2' ,
600
647
clientId : null ,
601
- redirectUri : null ,
648
+ redirectUri : window . location . origin ,
602
649
authorizationEndpoint : null ,
603
650
defaultUrlParams : [ 'response_type' , 'client_id' , 'redirect_uri' ] ,
604
651
requiredUrlParams : null ,
@@ -619,6 +666,46 @@ var defaultOptions = {
619
666
}
620
667
} ;
621
668
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
+
622
709
var LocalStorage = function LocalStorage ( namespace ) {
623
710
this . namespace = namespace || null ;
624
711
} ;
@@ -703,7 +790,10 @@ function StorageFactory(options) {
703
790
window . sessionStorage . setItem ( 'testKey' , 'test' ) ;
704
791
window . sessionStorage . removeItem ( 'testKey' ) ;
705
792
return new LocalStorage$2 ( options . storageNamespace )
706
- } catch ( e ) { }
793
+ } catch ( e ) { }
794
+
795
+ case 'cookieStorage' :
796
+ return new CookieStorage ( options . cookieStorage ) ;
707
797
708
798
case 'memoryStorage' :
709
799
default :
@@ -793,7 +883,9 @@ OAuthPopup.prototype._stringifyOptions = function _stringifyOptions () {
793
883
794
884
var options = [ ] ;
795
885
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
+ }
797
889
}
798
890
return options . join ( ',' )
799
891
} ;
@@ -809,7 +901,7 @@ var defaultProviderConfig = {
809
901
requiredUrlParams : null ,
810
902
defaultUrlParams : null ,
811
903
oauthType : '1.0' ,
812
- popupOptions : { width : null , height : null }
904
+ popupOptions : { }
813
905
} ;
814
906
815
907
var OAuth = function OAuth ( $http , storage , providerConfig , options ) {
@@ -928,7 +1020,7 @@ var defaultProviderConfig$1 = {
928
1020
redirectUri : 'redirectUri'
929
1021
} ,
930
1022
oauthType : '2.0' ,
931
- popupOptions : { width : null , height : null }
1023
+ popupOptions : { }
932
1024
} ;
933
1025
934
1026
var OAuth2 = function OAuth2 ( $http , storage , providerConfig , options ) {
@@ -1289,8 +1381,6 @@ VueAuthenticate.prototype.authenticate = function authenticate (provider, userDa
1289
1381
} else {
1290
1382
return reject ( new Error ( 'Authentication failed' ) )
1291
1383
}
1292
- } ) . catch ( function ( ) {
1293
- reject ( new Error ( 'Authentication error occurred' ) ) ;
1294
1384
} )
1295
1385
} )
1296
1386
} ;
0 commit comments