Skip to content

Commit

Permalink
Merge branch 'release/v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrubelic committed Sep 24, 2017
2 parents c822a12 + 7bf7d8a commit 14dc09b
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 178 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flow
dist
packages
19 changes: 19 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module"
},
"env": {
"browser": true,
},
"extends": "standard",
"plugins": [
"html"
],
"rules": {
"arrow-parens": 0,
"generator-star-spacing': 0
}
}

21 changes: 16 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
node_modules
bower_components

# Editors
Thumbs.db
.DS_Store

dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.iml

# OS metadata
.DS_Store
Thumbs.db
.vscode
settings.json
jsconfig.json
13 changes: 13 additions & 0 deletions .tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": {
"es_modules": {},
"node": {}
},
"libs": [
"ecma5",
"ecma6",
"react",
"browser"
],
"ecmaVersion": 6
}
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

[![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)

**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).
**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.

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.

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).

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.
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.

**DISCLAIMER**
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).

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

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.

## Supported OAuth providers and configurations

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

## Instalation
```bash
Expand Down Expand Up @@ -188,12 +195,15 @@ new Vue({
### Custom request and response interceptors

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

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

```javascript

/**
* This is example for request and response interceptors for axios library
*/

Vue.use(VueAuthenticate, {
bindRequestInterceptor: function () {
this.$http.interceptors.request.use((config) => {
Expand Down
65 changes: 36 additions & 29 deletions dist/vue-authenticate.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-authenticate v1.2.7
* vue-authenticate v1.3.0
* https://github.com/dgrubelic/vue-authenticate
* Released under the MIT License.
*/
Expand Down Expand Up @@ -451,10 +451,40 @@ var defaultOptions = {
logoutUrl: null,
storageType: 'localStorage',
storageNamespace: 'vue-authenticate',
requestDataKey: 'body',
responseDataKey: 'body',
bindRequestInterceptor: null,
bindResponseInterceptor: null,
requestDataKey: 'data',
responseDataKey: 'data',

/**
* Default request interceptor for Axios library
* @context {VueAuthenticate}
*/
bindRequestInterceptor: function () {
var this$1 = this;

this.$http.interceptors.request.use(function (config) {
if (this$1.isAuthenticated()) {
config.headers['Authorization'] = [
this$1.options.tokenType, this$1.getToken()
].join(' ');
} else {
delete config.headers['Authorization'];
}
return config
});
},

/**
* Default response interceptor for Axios library
* @contect {VueAuthenticate}
*/
bindResponseInterceptor: function () {
var this$1 = this;

this.$http.interceptors.response.use(function (response) {
this$1.setToken(response);
return response
});
},

providers: {
facebook: {
Expand Down Expand Up @@ -1032,8 +1062,6 @@ OAuth2.prototype._stringifyRequestParams = function _stringifyRequestParams () {
};

var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
var this$1 = this;

var options = objectExtend({}, defaultOptions);
options = objectExtend(options, overrideOptions);
var storage = StorageFactory(options);
Expand Down Expand Up @@ -1075,28 +1103,7 @@ var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
this.options.bindRequestInterceptor.call(this, this);
this.options.bindResponseInterceptor.call(this, this);
} else {
// By default, request and response interceptors are for vue-resource
this.$http.interceptors.push(function (request, next) {
if (this$1.isAuthenticated()) {
request.headers.set('Authorization', [
this$1.options.tokenType, this$1.getToken()
].join(' '));
} else {
request.headers.delete('Authorization');
}

next(function (response) {
try {
var responseJson = JSON.parse(response[this$1.options.responseDataKey]);
if (responseJson[this$1.options.tokenName]) {
this$1.setToken(responseJson);
delete responseJson[this$1.options.tokenName];
return responseJson
}
} catch(e) {}
return response
});
});
throw new Error('Both request and response interceptors must be functions')
}
};

Expand Down
65 changes: 36 additions & 29 deletions dist/vue-authenticate.es2015.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-authenticate v1.2.7
* vue-authenticate v1.3.0
* https://github.com/dgrubelic/vue-authenticate
* Released under the MIT License.
*/
Expand Down Expand Up @@ -449,10 +449,40 @@ var defaultOptions = {
logoutUrl: null,
storageType: 'localStorage',
storageNamespace: 'vue-authenticate',
requestDataKey: 'body',
responseDataKey: 'body',
bindRequestInterceptor: null,
bindResponseInterceptor: null,
requestDataKey: 'data',
responseDataKey: 'data',

/**
* Default request interceptor for Axios library
* @context {VueAuthenticate}
*/
bindRequestInterceptor: function () {
var this$1 = this;

this.$http.interceptors.request.use(function (config) {
if (this$1.isAuthenticated()) {
config.headers['Authorization'] = [
this$1.options.tokenType, this$1.getToken()
].join(' ');
} else {
delete config.headers['Authorization'];
}
return config
});
},

/**
* Default response interceptor for Axios library
* @contect {VueAuthenticate}
*/
bindResponseInterceptor: function () {
var this$1 = this;

this.$http.interceptors.response.use(function (response) {
this$1.setToken(response);
return response
});
},

providers: {
facebook: {
Expand Down Expand Up @@ -1030,8 +1060,6 @@ OAuth2.prototype._stringifyRequestParams = function _stringifyRequestParams () {
};

var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
var this$1 = this;

var options = objectExtend({}, defaultOptions);
options = objectExtend(options, overrideOptions);
var storage = StorageFactory(options);
Expand Down Expand Up @@ -1073,28 +1101,7 @@ var VueAuthenticate = function VueAuthenticate($http, overrideOptions) {
this.options.bindRequestInterceptor.call(this, this);
this.options.bindResponseInterceptor.call(this, this);
} else {
// By default, request and response interceptors are for vue-resource
this.$http.interceptors.push(function (request, next) {
if (this$1.isAuthenticated()) {
request.headers.set('Authorization', [
this$1.options.tokenType, this$1.getToken()
].join(' '));
} else {
request.headers.delete('Authorization');
}

next(function (response) {
try {
var responseJson = JSON.parse(response[this$1.options.responseDataKey]);
if (responseJson[this$1.options.tokenName]) {
this$1.setToken(responseJson);
delete responseJson[this$1.options.tokenName];
return responseJson
}
} catch(e) {}
return response
});
});
throw new Error('Both request and response interceptors must be functions')
}
};

Expand Down
Loading

0 comments on commit 14dc09b

Please sign in to comment.