|
| 1 | +# vue-authenticate |
| 2 | +`vue-authenticate` is easily configurable solution for *Vue.js* that provides local login/registration as well as Social login using Github, Facebook, Google and Twitter OAuth providers. |
| 3 | + |
| 4 | +The best part about this library is that it is not strictly coupled to one request handling library like `vue-resource`. You will be able to use it with different libraries. |
| 5 | + |
| 6 | +For now it is tested to work with `vue-resource` and `axios` (using `vue-axios` wrapper). |
| 7 | + |
| 8 | +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 | + |
| 10 | +## Instalation |
| 11 | +`npm install vue-authenticate` |
| 12 | + |
| 13 | +## Usage |
| 14 | +```javascript |
| 15 | +import Vue from 'vue' |
| 16 | +import VueResource from 'vue-resource' |
| 17 | +import VueAuthenticate from '../src/index.js' |
| 18 | + |
| 19 | +Vue.use(VueRouter) |
| 20 | +Vue.use(VueResource) |
| 21 | + |
| 22 | +Vue.use(VueAuthenticate, { |
| 23 | + baseUrl: 'http://localhost:4000', |
| 24 | + |
| 25 | + providers: { |
| 26 | + github: { |
| 27 | + clientId: '91b3c6a5b8411640e1b3', |
| 28 | + redirectUri: 'http://localhost:8080/auth/callback' |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | +
|
| 34 | +### Email & password login and registration |
| 35 | +```javascript |
| 36 | +new Vue({ |
| 37 | + methods: { |
| 38 | + login: function () { |
| 39 | + this.$auth.login({ email, password }).then(function () { |
| 40 | + // Execute application logic after successful login |
| 41 | + }) |
| 42 | + }, |
| 43 | + |
| 44 | + register: function () { |
| 45 | + this.$auth.register({ name, email, password }).then(function () { |
| 46 | + // Execute application logic after successful registration |
| 47 | + }) |
| 48 | + } |
| 49 | + } |
| 50 | +}) |
| 51 | +``` |
| 52 | +
|
| 53 | +### Social authentication |
| 54 | +
|
| 55 | +```javascript |
| 56 | +new Vue({ |
| 57 | + methods: { |
| 58 | + authenticate: function (provider) { |
| 59 | + this.$auth.authenticate(provider).then(function () { |
| 60 | + // Execute application logic after successful social authentication |
| 61 | + }) |
| 62 | + } |
| 63 | + } |
| 64 | +}) |
| 65 | +``` |
| 66 | +
|
| 67 | +```html |
| 68 | +<button @click="authenticate('github')">auth Github</button> |
| 69 | +<button @click="authenticate('facebook')">auth Facebook</button> |
| 70 | +<button @click="authenticate('google')">auth Google</button> |
| 71 | +<button @click="authenticate('twitter')">auth Twitter</button> |
| 72 | +``` |
| 73 | +
|
| 74 | +## License |
| 75 | +
|
| 76 | +The MIT License (MIT) |
| 77 | +
|
| 78 | +Copyright (c) 2017 Davor Grubelić |
| 79 | +
|
| 80 | +Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 81 | +this software and associated documentation files (the "Software"), to deal in |
| 82 | +the Software without restriction, including without limitation the rights to |
| 83 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 84 | +the Software, and to permit persons to whom the Software is furnished to do so, |
| 85 | +subject to the following conditions: |
| 86 | +
|
| 87 | +The above copyright notice and this permission notice shall be included in all |
| 88 | +copies or substantial portions of the Software. |
| 89 | +
|
| 90 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 91 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 92 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 93 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 94 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 95 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 commit comments