@websanova/vue-auth
Advanced tools
Comparing version 1.0.10-dev to 1.1.0-beta
@@ -17,3 +17,3 @@ { | ||
"version": "1.0.10-dev", | ||
"version": "1.1.0-beta", | ||
@@ -46,3 +46,3 @@ "repository": { | ||
"replace-webpack-plugin": "0.1.2", | ||
"@websanova/vue-auth": "1.0.10-dev" | ||
"@websanova/vue-auth": "1.1.0-beta" | ||
}, | ||
@@ -49,0 +49,0 @@ |
@@ -48,3 +48,3 @@ # Vue Auth | ||
**NOTE:** If you do not set your router as `Vue.router = new VueRouter()` then you will need to feed the `router` in directly through the options. | ||
**NOTE:** If you do not set your router as `Vue.router = new VueRouter()` then you will need to feed the `router` in directly through the options. Also true for `http`. | ||
@@ -54,3 +54,4 @@ ~~~ | ||
Vue.use(Auth, { | ||
router: router | ||
router: router, | ||
http: http | ||
}); | ||
@@ -377,8 +378,7 @@ ~~~ | ||
### token: `[{name: 'Authorization', authType: 'bearer', foundIn: 'header'}, {name: 'token', authType: 'bearer', foundIn: 'response'}]` | ||
* Set of method for fetching the token from the response. It will attempt each until a token is found and stop there. | ||
* For sending requests it will by default use the method in the first position. | ||
### tokenVar: `'token'` | ||
* The name of the token to check for in the response. | ||
### tokenName: `'auth-token'` | ||
@@ -388,10 +388,2 @@ | ||
### tokenHeader: `'Authorization'` | ||
* Name of authorization token header to look for in the response. | ||
### authType: `'bearer'` `'basic'` | ||
* Authentication type to use. | ||
### rolesVar: `'roles'` | ||
@@ -398,0 +390,0 @@ |
@@ -81,3 +81,3 @@ var __utils = require('./lib/utils.js'), | ||
if (token) { | ||
this.options[this.options.authType + 'Auth'].request.call(this, req, token); | ||
this.options[this.options.token[0].authType + 'Auth'].request.call(this, req, token); | ||
} | ||
@@ -89,11 +89,24 @@ | ||
function _responseIntercept(res) { | ||
var token = this.options._getHeaders.call(this, res).authorization || this.options._httpData.call(this, res)[this.options.tokenVar]; | ||
var i, ii, | ||
token, | ||
tokens = this.options.token; | ||
if (token) { | ||
this.options[this.options.authType + 'Auth'].response.call(this, res, token); | ||
} | ||
if (this.options._invalidToken) { | ||
this.options._invalidToken.call(this, res); | ||
} | ||
for (i = 0, ii = tokens.length; i < ii; i++) { | ||
if (tokens[i].foundIn === 'header') { | ||
token = this.options._getHeaders.call(this, res)[tokens[i].name]; | ||
} | ||
else if (tokens[i].foundIn === 'response') { | ||
token = this.options._httpData.call(this, res)[tokens[i].name]; | ||
} | ||
if (token) { | ||
this.options[tokens[i].authType + 'Auth'].response.call(this, res, token); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -325,10 +338,23 @@ | ||
// Tokens | ||
token: [{ | ||
name: 'Authorization', | ||
authType: 'bearer', | ||
foundIn: 'header' | ||
}, { | ||
name: 'token', | ||
authType: 'bearer', | ||
foundIn: 'response' | ||
}], | ||
// tokenVar: 'token', | ||
// tokenHeader: 'Authorization', | ||
// authType: 'bearer', | ||
// Variables | ||
tokenVar: 'token', | ||
rolesVar: 'roles', | ||
tokenName: 'auth-token', | ||
tokenHeader: 'Authorization', | ||
authType: 'bearer', | ||
rolesVar: 'roles', | ||
// Objects | ||
@@ -407,5 +433,7 @@ | ||
request: function (req, token) { | ||
this.options._setHeaders.call(this, req, { | ||
authorization: 'Bearer ' + token | ||
}); | ||
var data = {}; | ||
data[this.options.token[0].name] = 'Bearer ' + token; | ||
this.options._setHeaders.call(this, req, data); | ||
}, | ||
@@ -420,5 +448,7 @@ response: function (res, token) { | ||
request: function (req, token) { | ||
this.options._setHeaders.call(this, req, { | ||
authorization: token | ||
}); | ||
var data = {}; | ||
data[this.options.token[0].name] = token; | ||
this.options._setHeaders.call(this, req, token); | ||
}, | ||
@@ -425,0 +455,0 @@ response: function (res, token) { |
@@ -26,10 +26,18 @@ module.exports = { | ||
_getHeaders: function (res) { | ||
return { | ||
authorization: res.headers.get(this.options.tokenHeader) | ||
}; | ||
var i, | ||
data = {}, | ||
headers = res.headers.map; | ||
for (i in headers) { | ||
data[i] = headers[i][0]; | ||
} | ||
return data; | ||
}, | ||
_setHeaders: function (req, headers) { | ||
if (headers.authorization) { | ||
req.headers.set(this.options.tokenHeader, headers.authorization); | ||
var i; | ||
for (i in headers) { | ||
req.headers.set(i, headers[i]); | ||
} | ||
@@ -36,0 +44,0 @@ }, |
module.exports = (function (){ | ||
function isObject(val) { | ||
if (val !== null && typeof val === 'object' && val.constructor !== Array ) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function toArray(val) { | ||
@@ -11,4 +19,4 @@ return (typeof val) === 'string' ? [val] : val; | ||
for (key in mainObj) { | ||
if (typeof mainObj[key] === 'object') { | ||
data[key] = extend(mainObj[key], []); | ||
if (isObject(mainObj[key])) { | ||
data[key] = extend(mainObj[key], {}); | ||
} | ||
@@ -22,3 +30,3 @@ else { | ||
for (key in appendObj[i]) { | ||
if (typeof appendObj[i][key] === 'object') { | ||
if (isObject(appendObj[i][key])) { | ||
data[key] = extend(mainObj[key] || {}, [appendObj[i][key]]); | ||
@@ -25,0 +33,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217552
2209
526