Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

vue-jwt-auth

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-jwt-auth - npm Package Compare versions

Comparing version
0.8.1
to
0.9.0
+1
-1
package.json

@@ -19,3 +19,3 @@ {

},
"version": "0.8.1"
"version": "0.9.0"
}
+60
-36

@@ -90,15 +90,15 @@ # vue-jwt-auth

`**true**`
**`true`**
User must be authenticated (no roles are checked).
`**false**`
**`false`**
If the user is logged in then this route will be unavailable. Useful for login/register type pages to be unaccessible once the user is logged in.
`**undefined**`
**`undefined`**
Public, no checks required.
`**Array**` or `**String**`
**`Array`** or **`String`**

@@ -112,3 +112,3 @@ The user must be logged in. Additionally the string or array will be checked against the users roles.

`**ready()**`
**`ready()`**

@@ -119,3 +119,3 @@ When the app boots the `vue-jwt-auth` plugin will fire off a check for a token and subsequent user fetch. In the first instance of this the app will be set to "ready".

`**check()**`
**`check()`**

@@ -131,3 +131,3 @@ Check if the user is logged in. It can also be used to check if the user has a specific role.

`**user()**`
**`user()`**

@@ -137,3 +137,3 @@ Fetch the user object stored in the `$auth` instance.

`**login()**`
**`login()`**

@@ -158,3 +158,3 @@ Login the user which accepts four parameters.

`**facebook()**` `**google()**`
**`facebook()`** **`google()`**

@@ -193,3 +193,3 @@ These follows the same format as the `$auth.login()` method.

`**logout()**`
**`logout()`**

@@ -212,15 +212,23 @@ Log the user out.

`**loginAs(data, redirectUrl, options)**`
**`loginAs(data, redirectUrl, options)`**
Login as another user.
`**logoutAs(redirectUrl)**`
**`logoutAs(redirectUrl)`**
Logout or other user. Will revert to previously logged in user.
`**other()**`
**`other()`**
Check if we are currently logged in as another user.
**`getAuthHeader()`**
Returns the auth header. Useful when integration third part libraries.
**`version()`**
Returns current version.
## Options

@@ -230,10 +238,14 @@

`**authType**`
**`authType`**
**default:** 'bearer'
Set the auth type. Only `bearer` is supported at this time.
**`tokenType`**
`**fetchUrl**`
**default:** 'jwt'
If set to 'jwt' will check expiry time for refreshes, otherwise no other implementation exists and it will just send the token directly.
**`fetchUrl`**
**default:** '/auth/user'

@@ -243,3 +255,3 @@

`**tokenUrl**`
**`tokenUrl`**

@@ -250,3 +262,3 @@ **default:** '/auth/token'

`**loginUrl**`
**`loginUrl`**

@@ -257,3 +269,3 @@ **default:** '/auth/login'

`**registerUrl**`
**`registerUrl`**

@@ -264,3 +276,3 @@ **default:** '/auth/register'

`**loginRedirect**`
**`loginRedirect`**

@@ -271,3 +283,3 @@ **default:** '/login'

`**notFoundRedirect**`
**`notFoundRedirect`**

@@ -278,3 +290,3 @@ **default:** '/404'

`**forbiddenRedirect**`
**`forbiddenRedirect`**

@@ -285,3 +297,3 @@ **default:** '/403'

`**rolesVar**`
**`rolesVar`**

@@ -292,3 +304,3 @@ **default:** 'roles'

`**tokenVar**`
**`tokenVar`**

@@ -299,3 +311,3 @@ **default:** 'token'

`**tokenName**`
**`tokenName`**

@@ -306,4 +318,10 @@ **default:** 'jwt-auth-token'

`**cookieDomain**`
**`tokenTimeoutOffset`**
**default:** 5000
Offset for token timeout (for some buffer).
**`cookieDomain`**
**default:** _cookieDomain

@@ -313,3 +331,3 @@

`**userData**`
**`userData`**

@@ -320,3 +338,3 @@ **default:** _userData

`**beforeEach**`
**`beforeEach`**

@@ -327,4 +345,10 @@ **default:** _beforeEach

`**facebookUrl**`
**`invalidToken`**
**default:** _invalidToken
Method to run if a `401` is hit during an API request. By default will run logout.
**`facebookUrl`**
**default:** '/auth/facebook'

@@ -334,3 +358,3 @@

`**facebookAppId**`
**`facebookAppId`**

@@ -341,3 +365,3 @@ **default:** ''

`**facebookScope**`
**`facebookScope`**

@@ -348,3 +372,3 @@ **default:** 'email'

`**facebookRedirect**`
**`facebookRedirect`**

@@ -355,3 +379,3 @@ **default:** _getUrl() + '/login/facebook'

`**googleUrl**`
**`googleUrl`**

@@ -362,3 +386,3 @@ **default:** '/auth/google'

`**googleAppId**`
**`googleAppId`**

@@ -369,3 +393,3 @@ **default:** ''

`**googleScope**`
**`googleScope`**

@@ -376,3 +400,3 @@ **default:** 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'

`**googleRedirect**`
**`googleRedirect`**

@@ -379,0 +403,0 @@ **default:** _getUrl() + '/login/google'

@@ -26,2 +26,4 @@ module.exports = (function () {

function _userData (res) {
res = res.json();
return res.data || res

@@ -71,2 +73,33 @@ }

function _http (options) {
// Version 0.8.0
this.$http[options.method || 'get'](options.url, options.data).then(options.success, options.error);
}
function _interceptor (Vue, req, res) {
// Version 0.8.0
Vue.http.interceptors.push((request, next) => {
if (req) { req.call(this, request); }
next((response) => {
if (res) { res.call(this, response); }
});
});
// // Version before Promise implementation.
// else {
// Vue.http.interceptors.push({
// request (request) {
// if (req) { req.call(this, request); }
// },
// response (response) {
// if (res) { res.call(this, response); }
// }
// });
// }
}
// Remember Me

@@ -110,17 +143,21 @@

function _refreshToken () {
var _this = this
var _this = this;
if (_getToken.call(this)) {
this.$http.get(this.getOption('tokenUrl'), function (res) {
var tokenJSON = _decodeToken(_getToken.call(_this)),
expireTime = _getTokenExpirationDate(tokenJSON).valueOf(),
nowTime = new Date().valueOf(),
offsetTime = this.getOption('tokenTimeoutOffset'),
timeout = expireTime - nowTime - offsetTime;
if (_getToken.call(this) && this.getOption('tokenType') === 'jwt') {
_http.call(this, {
url: this.getOption('tokenUrl'),
method: 'get',
success: () => {
var tokenJSON = _decodeToken(_getToken.call(_this)),
expireTime = _getTokenExpirationDate(tokenJSON).valueOf(),
nowTime = new Date().valueOf(),
offsetTime = this.getOption('tokenTimeoutOffset'),
timeout = expireTime - nowTime - offsetTime;
clearTimeout(_tokenRefreshTimeout)
clearTimeout(_tokenRefreshTimeout);
_tokenRefreshTimeout = setTimeout(function () {
_refreshToken.call(_this)
}, timeout)
_tokenRefreshTimeout = setTimeout(function () {
_refreshToken.call(_this);
}, timeout);
}
});

@@ -187,27 +224,31 @@ }

this.$http.post(path, data, function (res) {
var _this = this
_http.call(this, {
url: path,
method: 'post',
data: data,
success: (res) => {
var _this = this
_setRememberMeCookie.call(this, rememberMe)
_setRememberMeCookie.call(this, rememberMe);
_setToken.call(this, res[this.getOption('tokenVar')])
_setToken.call(this, res.json()[this.getOption('tokenVar')]);
this.authenticated = null
this.authenticated = null;
this.fetch(function () {
if (options.success) {
options.success.call(_this, res)
}
this.fetch(function () {
if (options.success) {
options.success.call(_this, res);
}
if (redirectUrl && _this.check()) {
_this.$router.go(redirectUrl)
}
})
}, {
error (res) {
if (redirectUrl && _this.check()) {
_this.$router.go(redirectUrl);
}
});
},
error: (res) => {
if (options.error) {
options.error.call(this, res)
options.error.call(this, res);
}
}
})
});
}

@@ -251,15 +292,18 @@

this.$http.get(this.getOption('fetchUrl'), function (res) {
this.authenticated = true
this.data = this.getOption('userData').call(this, res)
this.loaded = true
_http.call(this, {
url: this.getOption('fetchUrl'),
method: 'get',
success: (res) => {
this.authenticated = true;
this.data = this.getOption('userData').call(this, res);
this.loaded = true;
return cb()
}, {
error () {
this.loaded = true
return cb();
},
error: () => {
this.loaded = true;
return cb()
return cb();
}
})
});
}

@@ -272,2 +316,3 @@

authType: 'bearer',
tokenType: 'jwt',

@@ -358,4 +403,2 @@ fetchUrl: 'auth/user',

check (role) {
var token = _getToken.call(this)
if (this.data !== null) {

@@ -411,23 +454,27 @@ if (role) {

this.$http.post(this.getOption('loginAsUrl'), data, function (res) {
var _this = this
_http.call(this, {
url: this.getOption('loginAsUrl'),
method: 'post',
data: data,
success: (res) => {
var _this = this;
localStorage.setItem('login-as-' + this.getOption('tokenName'), res[this.getOption('tokenVar')])
localStorage.setItem('login-as-' + this.getOption('tokenName'), res.json()[this.getOption('tokenVar')]);
_fetch.call(this, function () {
if (options.success) {
options.success.call(this, res)
}
_fetch.call(this, function () {
if (options.success) {
options.success.call(this, res);
}
if (redirectUrl && _this.check()) {
_this.$router.go(redirectUrl)
}
})
}, {
error (res) {
if (redirectUrl && _this.check()) {
_this.$router.go(redirectUrl);
}
})
},
error: (res) => {
if (options.error) {
options.error.call(this, res)
options.error.call(this, res);
}
}
})
});
},

@@ -451,2 +498,18 @@

return localStorage.getItem('login-as-' + this.getOption('tokenName'))
},
// Token
getAuthHeader() {
var token = _getToken.call(this);
if (token && this.getOption('authType') === 'bearer') {
return 'Bearer: ' + token;
}
return false;
},
version() {
return '0.9.0';
}

@@ -481,36 +544,28 @@ }

// Set interceptors.
Vue.http.interceptors.push({
// Send auth token on each request.
request (req) {
var token = _getToken.call(auth)
_interceptor(Vue, (req) => {
var token = _getToken.call(auth)
if (token && auth.getOption('authType') === 'bearer') {
req.headers.Authorization = 'Bearer: ' + token
}
return req
},
if (token && auth.getOption('authType') === 'bearer') {
req.headers.Authorization = 'Bearer: ' + token
}
},
// Reset auth token if provided in response.
response (res) {
var authorization = res.headers('Authorization'),
invalidTokenMethod = auth.getOption('invalidToken')
// Reset auth token if provided in response.
(res) => {
var authorization = res.headers.Authorization,
invalidTokenMethod = auth.getOption('invalidToken')
if (authorization) {
authorization = authorization.split(' ')
if (authorization) {
authorization = authorization.split(' ')
if (authorization[1]) {
_setToken.call(auth, authorization[1])
}
if (authorization[1]) {
_setToken.call(auth, authorization[1])
}
}
if (invalidTokenMethod) {
invalidTokenMethod.bind(auth)(res)
}
return res
if (invalidTokenMethod) {
invalidTokenMethod.bind(auth)(res)
}
})
});
}
})()
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2A.2F=(8(){j 1n=v 8 1N(D){j 9=T(D.2f.9)c(9&&(9===q||9.14===1f)){c(!6.V()){6.$n.U(6.e(\'2E\'))}A c(9.14===1f&&!1x(9,T(6.1G()[6.e(\'1I\')]))){6.$n.U(6.e(\'1V\'))}A{b D.2n()}}A c(9===u&&6.V()){6.$n.U(6.e(\'1X\'))}A{b D.2n()}}8 1Q(m){b m.7||m}8 1O(){b B.F.29}8 1s(){j 11=B.F.11 b B.F.2C+\'//\'+B.F.29+(11?\':\'+11:\'\')}8 1x(J,Z){j i,1E J=T(J)Z=T(Z)c(J.14!==1f||Z.14!==1f){b u}2p(i=0,1E=J.1F;i<1E;i++){c(Z.2Y(J[i])>=0){b q}}b u}8 T(15){b(20 15)===\'22\'?[15]:15}8 1v(2v,2y,1t){j 1w=6.e(\'1M\').f(6)j 1l=(z 1d((z 1d()).2U()+1t)).2Q()2a.28=(2v+\'=\'+2y+\'; 1w=\'+1w+\'; 1g=/;\'+(1t?\' 1l=\'+1l+\';\':\'\'))}8 1P(l){1v.f(6,\'l\',l===q?\'q\':\'u\',l===q?2q:21)}8 2d(){1v.f(6,\'l\',\'u\',-2q)}8 1o(k){c(k){I.2l((6.1a()?\'p-C-\':\'\')+6.e(\'E\'),k)}}8 X(){b I.2i((6.1a()?\'p-C-\':\'\')+6.e(\'E\'))}8 16(){I.2j((6.1a()?\'p-C-\':\'\')+6.e(\'E\'))}8 1J(){j t=6 c(X.f(6)){6.$10.1C(6.e(\'1Y\'))2M(1n)1n=2O(8(){1J.f(t)},6.e(\'1W\'))}}8 1K(2w){O S=2w.U(/-/g,\'+\').U(/2N/g,\'/\')2S(S.1F%4){1p 0:{1r}1p 2:{S+=\'==\'1r}1p 3:{S+=\'=\'1r}2L:{2I.2J(\'2K 2P 22!\')}}b 2W(2X(B.2V(S)))}8 1k(k){O 1b=k.2u(\'.\')c(1b.1F!==3){23 z 24(\'2R 2H 2T 3 1b\')}O K=1K(1b[1])c(!K){23 z 24(\'2G 2B 2D k\')}b 1y.25(K)}8 1R(k){O K=1k(k)c(20 K.1u===\'21\'){b v}O d=z 1d(0)d.2z(K.1u)b d}8 27(k,17){O d=1R(k)17=17||0 c(d===v){b u}b!(d.1T()>(z 1d().1T()+(17*1L)))}8 2g(P,n){6.$P=P 6.$n=n}8 1i(1g,7,l,h,a){a=a||{}6.$10.2e(1g,7,8(m){j t=6 1P.f(6,l)1o.f(6,m[6.e(\'1B\')])6.L=v 6.1z(8(){c(a.12){a.12.f(t,m)}c(h&&t.V()){t.$n.19(h)}})},{y(m){c(a.y){a.y.f(6,m)}}})}8 1j(w,7,l,h,a){j s j N=\'\'7=7||{}c(7.1U){s=1y.25(6.$P.3B.s)1i.f(6,6.e(w+\'3A\'),7,s.l,s.Y,a)}A{7.s=7.s||{}7.s.l=l===q 7.s.Y=h||\'\'7.1D=7.1D||6.e(w+\'3C\')7.1Z=7.1Z||6.e(w+\'3D\')7.1c=7.1c||6.e(w+\'3E\')7.Y=7.Y||6.e(w+\'3z\')N=\'?3y=\'+7.1D+\'&3u=\'+7.Y+\'&1c=\'+7.1c+\'&3t=1U&s=\'+1y.3v(7.s)c(w===\'G\'){B.F=\'Q://18.G.R/3w.5/3x/3G\'+N}A c(w===\'M\'){B.F=\'Q://3F.M.R/o/3O/9\'+N}}}8 1e(r){r=r||8(){}6.$10.1C(6.e(\'26\'),8(m){6.L=q 6.7=6.e(\'1S\').f(6,m)6.x=q b r()},{y(){6.x=q b r()}})}j 2h={a:{1h:\'/3P\',2m:\'2x\',26:\'9/1G\',1Y:\'9/k\',2o:\'9/p\',2k:\'9/p-C\',3M:\'/\',1X:\'/3I\',1V:\'/3N\',1I:\'3H\',1B:\'k\',E:\'3J-9-k\',1W:3K*1L,1M:1O,1S:1Q,1A:1N,3L:\'9/G\',3s:\'\',2Z:\'3r\',39:1s()+\'/p/G\',38:\'9/M\',3a:\'\',3b:\'Q://18.1m.R/9/1q.3c Q://18.1m.R/9/1q.p Q://18.1m.R/9/1q.37.36.31\',30:1s()+\'/p/M\'},7(){b{7:v,x:u,L:v}},32:{e(2t){b 6.$a.a[2t]},2c(a){2p(j i 33 a){6.$a.a[i]=a[i]}},p(7,l,h,a){1i.f(6,6.e(\'2o\'),7,l,h,a)},G(7,l,h,a){1j.f(6,\'G\',7,l,h,a)},M(7,l,h,a){1j.f(6,\'M\',7,l,h,a)},35(h,2b){2d.f(6)16.f(6)16.f(6)6.L=u 6.7=v c(h&&(6.$P.9||2b)){6.$n.19(h)}},V(1H){c(6.7===v){b q}j k=X.f(6)j N=1k(k)b 27(k,N.1u)&&(!1H||1x(1H,6.7[6.e(\'1I\')]))},1z(r){r=r||8(){}c(!6.x){1J.f(6)}c(6.L===v&&X.f(6)){c(!2a.28.34(/l/)){16.f(6)6.x=q b r()}6.L=u 1e.f(6,r)}A{6.x=q b r()}},1G(){b 6.7},3d(){b 6.x},3e(7,h,a){a=a||{}6.$10.2e(6.e(\'2k\'),7,8(m){j t=6 I.2l(\'p-C-\'+6.e(\'E\'),m[6.e(\'1B\')])1e.f(6,8(){c(a.12){a.12.f(6,m)}c(h&&t.V()){t.$n.19(h)}})},{y(m){c(a.y){a.y.f(6,m)}}})},3n(h){j t=6 I.2j(\'p-C-\'+6.e(\'E\'))1e.f(6,8(){c(h){t.$n.19(h)}})},1a(){6.7 b I.2i(\'p-C-\'+6.e(\'E\'))}}}b 8 3m(W,a,n){j 9=z W(2h)9.2c(a||{})3o.3p(W.3q,{$9:{1C(){2g.f(9,6.$P,6.$n)b 9}}});(W.n||n).1A(8(D){D.2f.n.3l.$9.1z(8(){9.e(\'1A\').3k(9)(D)})})W.10.3g.3f({3h(13){j k=X.f(9)c(k&&9.e(\'2m\')===\'2x\'&&13.1h===9.e(\'1h\')){13.2r.2s=\'3i: \'+k}b 13},3j(m){j H=m.2r(\'2s\')c(H){H=H.2u(\' \')c(H[1]){1o.f(9,H[1])}}b m}})}})()',62,238,'||||||this|data|function|auth|options|return|if||getOption|call||redirectUrl||var|token|rememberMe|res|router||login|true|cb|state|_this|false|null|type|loaded|error|new|else|window|as|transition|tokenName|location|facebook|authorization|localStorage|one|decoded|authenticated|google|params|let|route|https|com|output|_toArray|replace|check|Vue|_getToken|redirect|two|http|port|success|req|constructor|val|_removeToken|offsetSeconds|www|go|other|parts|scope|Date|_fetch|Array|path|root|_login|_social|_decodeToken|expires|googleapis|_tokenRefreshTimeout|_setToken|case|plus|break|_getUrl|timeOffset|exp|_setCookie|domain|_compare|JSON|fetch|beforeEach|tokenVar|get|appId|ii|length|user|role|rolesVar|_refreshToken|_urlBase64Decode|1000|cookieDomain|_beforeEach|_cookieDomain|_setRememberMeCookie|_userData|_getTokenExpirationDate|userData|valueOf|code|forbiddenRedirect|tokenTimeout|notFoundRedirect|tokenUrl|clientId|typeof|undefined|string|throw|Error|parse|fetchUrl|_isTokenExpired|cookie|hostname|document|force|setOptions|_removeRememberMeCookie|post|to|_setRoute|Auth|getItem|removeItem|loginAsUrl|setItem|authType|next|loginUrl|for|12096e5|headers|Authorization|key|split|name|str|bearer|value|setUTCSeconds|module|decode|protocol|the|authRedirect|exports|Cannot|must|console|log|Illegal|default|clearTimeout|_|setTimeout|base64url|toUTCString|JWT|switch|have|getTime|atob|decodeURIComponent|escape|indexOf|facebookScope|googleRedirect|read|methods|in|match|logout|emails|profile|googleUrl|facebookRedirect|googleAppId|googleScope|me|ready|loginAs|push|interceptors|request|Bearer|response|bind|app|install|logoutAs|Object|defineProperties|prototype|email|facebookAppId|response_type|redirect_uri|stringify|v2|dialog|client_id|Redirect|Url|query|AppId|ClientId|Scope|accounts|oauth|roles|404|jwt|3000|facebookUrl|logoutRedirect|403|oauth2|api'.split('|'),0,{}))