Skip to content

Commit 14dc09b

Browse files
committed
Merge branch 'release/v1.3.0'
2 parents c822a12 + 7bf7d8a commit 14dc09b

17 files changed

+303
-178
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flow
2+
dist
3+
packages

.eslintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"sourceType": "module"
6+
},
7+
"env": {
8+
"browser": true,
9+
},
10+
"extends": "standard",
11+
"plugins": [
12+
"html"
13+
],
14+
"rules": {
15+
"arrow-parens": 0,
16+
"generator-star-spacing': 0
17+
}
18+
}
19+

.gitignore

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
node_modules
44
bower_components
55

6-
# Editors
6+
Thumbs.db
7+
.DS_Store
8+
9+
dist/
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
715
.idea
16+
*.suo
17+
*.ntvs*
18+
*.njsproj
19+
*.sln
820
*.iml
9-
10-
# OS metadata
11-
.DS_Store
12-
Thumbs.db
21+
.vscode
22+
settings.json
23+
jsconfig.json

.tern-project

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"plugins": {
3+
"es_modules": {},
4+
"node": {}
5+
},
6+
"libs": [
7+
"ecma5",
8+
"ecma6",
9+
"react",
10+
"browser"
11+
],
12+
"ecmaVersion": 6
13+
}

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
[![Join the chat at https://gitter.im/vuejs-auth/vue-authenticate](https://badges.gitter.im/vue-authenticate/Lobby.svg)](https://gitter.im/vuejs-auth/vue-authenticate?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

5-
**vue-authenticate** is easily configurable solution for [Vue.js](https://vuejs.org/) that provides local login/registration as well as Social login using Github, Facebook, Google and Twitter OAuth providers (only those 4 tested for now).
5+
**vue-authenticate** is easily configurable solution for [Vue.js](https://vuejs.org/) that provides local login/registration as well as Social login using Github, Facebook, Google and other OAuth providers.
66

7-
The best part about this library is that it is not strictly coupled to one request handling library like [vue-resource](https://github.com/pagekit/vue-resource). You will be able to use it with different libraries.
87

9-
For now it is tested to work with [vue-resource](https://github.com/pagekit/vue-resource) (default library) and [axios](https://github.com/mzabriskie/axios) (using [vue-axios](https://github.com/imcvampire/vue-axios) wrapper).
108

11-
This library was inspired by well known authentication library for Angular called [Satellizer](https://github.com/sahat/satellizer) developed by [Sahat Yalkabov](http://sahatyalkabov.com). They share almost identical configuration and API so you can easily switch from Angular to Vue.js project.
9+
The best part about this library is that it is not strictly coupled to one request handling library like [vue-axios](https://github.com/imcvampire/vue-axios). You will be able to use it with different libraries.
1210

13-
**DISCLAIMER**
11+
For now it is tested to work with [vue-resource](https://github.com/pagekit/vue-resource) and [axios](https://github.com/mzabriskie/axios) (using [vue-axios](https://github.com/imcvampire/vue-axios) wrapper).
1412

15-
For now, this package only supports ES6 import usage, but soon will have standalone ES5 build.
13+
**WARNING** From version 1.3.0 default request library is `axios` using `vue-axios` wrapper plugin.
1614

15+
This library was inspired by well known authentication library for Angular called [Satellizer](https://github.com/sahat/satellizer) developed by [Sahat Yalkabov](http://sahatyalkabov.com). They share almost identical configuration and API so you can easily switch from Angular to Vue.js project.
1716

17+
## Supported OAuth providers and configurations
1818

19-
*DEMO app comming soon...*
19+
1. Facebook (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L21)
20+
2. Google (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L34)
21+
3. Github (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L49)
22+
4. Instagram (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L61)
23+
5. Twitter (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L72)
24+
6. Bitbucket (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L81)
25+
7. LinkedIn (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L93)
26+
8. Microsoft Live (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L106)
2027

2128
## Instalation
2229
```bash
@@ -188,12 +195,15 @@ new Vue({
188195
### Custom request and response interceptors
189196

190197
You can easily setup custom request and response interceptors if you use different request handling library.
191-
Fro example, if you use **axios** in your app, request and response interceptors would look something like this:
192198

193-
**Important**: You must set both `request` and `response` interceptors if your uses request handling library other than `vue-resource` (default library).
199+
**Important**: You must set both `request` and `response` interceptors at all times.
194200

195201
```javascript
196202

203+
/**
204+
* This is example for request and response interceptors for axios library
205+
*/
206+
197207
Vue.use(VueAuthenticate, {
198208
bindRequestInterceptor: function () {
199209
this.$http.interceptors.request.use((config) => {

dist/vue-authenticate.common.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-authenticate v1.2.7
2+
* vue-authenticate v1.3.0
33
* https://github.com/dgrubelic/vue-authenticate
44
* Released under the MIT License.
55
*/
@@ -451,10 +451,40 @@ var defaultOptions = {
451451
logoutUrl: null,
452452
storageType: 'localStorage',
453453
storageNamespace: 'vue-authenticate',
454-
requestDataKey: 'body',
455-
responseDataKey: 'body',
456-
bindRequestInterceptor: null,
457-
bindResponseInterceptor: null,
454+
requestDataKey: 'data',
455+
responseDataKey: 'data',
456+
457+
/**
458+
* Default request interceptor for Axios library
459+
* @context {VueAuthenticate}
460+
*/
461+
bindRequestInterceptor: function () {
462+
var this$1 = this;
463+
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()
468+
].join(' ');
469+
} else {
470+
delete config.headers['Authorization'];
471+
}
472+
return config
473+
});
474+
},
475+
476+
/**
477+
* Default response interceptor for Axios library
478+
* @contect {VueAuthenticate}
479+
*/
480+
bindResponseInterceptor: function () {
481+
var this$1 = this;
482+
483+
this.$http.interceptors.response.use(function (response) {
484+
this$1.setToken(response);
485+
return response
486+
});
487+
},
458488

459489
providers: {
460490
facebook: {
@@ -1032,8 +1062,6 @@ OAuth2.prototype._stringifyRequestParams = function _stringifyRequestParams () {
10321062
};
10331063

10341064
var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
1035-
var this$1 = this;
1036-
10371065
var options = objectExtend({}, defaultOptions);
10381066
options = objectExtend(options, overrideOptions);
10391067
var storage = StorageFactory(options);
@@ -1075,28 +1103,7 @@ var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
10751103
this.options.bindRequestInterceptor.call(this, this);
10761104
this.options.bindResponseInterceptor.call(this, this);
10771105
} else {
1078-
// By default, request and response interceptors are for vue-resource
1079-
this.$http.interceptors.push(function (request, next) {
1080-
if (this$1.isAuthenticated()) {
1081-
request.headers.set('Authorization', [
1082-
this$1.options.tokenType, this$1.getToken()
1083-
].join(' '));
1084-
} else {
1085-
request.headers.delete('Authorization');
1086-
}
1087-
1088-
next(function (response) {
1089-
try {
1090-
var responseJson = JSON.parse(response[this$1.options.responseDataKey]);
1091-
if (responseJson[this$1.options.tokenName]) {
1092-
this$1.setToken(responseJson);
1093-
delete responseJson[this$1.options.tokenName];
1094-
return responseJson
1095-
}
1096-
} catch(e) {}
1097-
return response
1098-
});
1099-
});
1106+
throw new Error('Both request and response interceptors must be functions')
11001107
}
11011108
};
11021109

dist/vue-authenticate.es2015.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-authenticate v1.2.7
2+
* vue-authenticate v1.3.0
33
* https://github.com/dgrubelic/vue-authenticate
44
* Released under the MIT License.
55
*/
@@ -449,10 +449,40 @@ var defaultOptions = {
449449
logoutUrl: null,
450450
storageType: 'localStorage',
451451
storageNamespace: 'vue-authenticate',
452-
requestDataKey: 'body',
453-
responseDataKey: 'body',
454-
bindRequestInterceptor: null,
455-
bindResponseInterceptor: null,
452+
requestDataKey: 'data',
453+
responseDataKey: 'data',
454+
455+
/**
456+
* Default request interceptor for Axios library
457+
* @context {VueAuthenticate}
458+
*/
459+
bindRequestInterceptor: function () {
460+
var this$1 = this;
461+
462+
this.$http.interceptors.request.use(function (config) {
463+
if (this$1.isAuthenticated()) {
464+
config.headers['Authorization'] = [
465+
this$1.options.tokenType, this$1.getToken()
466+
].join(' ');
467+
} else {
468+
delete config.headers['Authorization'];
469+
}
470+
return config
471+
});
472+
},
473+
474+
/**
475+
* Default response interceptor for Axios library
476+
* @contect {VueAuthenticate}
477+
*/
478+
bindResponseInterceptor: function () {
479+
var this$1 = this;
480+
481+
this.$http.interceptors.response.use(function (response) {
482+
this$1.setToken(response);
483+
return response
484+
});
485+
},
456486

457487
providers: {
458488
facebook: {
@@ -1030,8 +1060,6 @@ OAuth2.prototype._stringifyRequestParams = function _stringifyRequestParams () {
10301060
};
10311061

10321062
var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
1033-
var this$1 = this;
1034-
10351063
var options = objectExtend({}, defaultOptions);
10361064
options = objectExtend(options, overrideOptions);
10371065
var storage = StorageFactory(options);
@@ -1073,28 +1101,7 @@ var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
10731101
this.options.bindRequestInterceptor.call(this, this);
10741102
this.options.bindResponseInterceptor.call(this, this);
10751103
} else {
1076-
// By default, request and response interceptors are for vue-resource
1077-
this.$http.interceptors.push(function (request, next) {
1078-
if (this$1.isAuthenticated()) {
1079-
request.headers.set('Authorization', [
1080-
this$1.options.tokenType, this$1.getToken()
1081-
].join(' '));
1082-
} else {
1083-
request.headers.delete('Authorization');
1084-
}
1085-
1086-
next(function (response) {
1087-
try {
1088-
var responseJson = JSON.parse(response[this$1.options.responseDataKey]);
1089-
if (responseJson[this$1.options.tokenName]) {
1090-
this$1.setToken(responseJson);
1091-
delete responseJson[this$1.options.tokenName];
1092-
return responseJson
1093-
}
1094-
} catch(e) {}
1095-
return response
1096-
});
1097-
});
1104+
throw new Error('Both request and response interceptors must be functions')
10981105
}
10991106
};
11001107

0 commit comments

Comments
 (0)