{"id":13536015,"url":"https://github.com/dgrubelic/vue-authenticate","last_synced_at":"2025-05-14T21:04:56.147Z","repository":{"id":19294742,"uuid":"86714667","full_name":"dgrubelic/vue-authenticate","owner":"dgrubelic","description":"Simple Vue.js authentication library","archived":false,"fork":false,"pushed_at":"2024-03-14T17:33:56.000Z","size":699,"stargazers_count":1432,"open_issues_count":115,"forks_count":248,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-04-29T06:02:35.517Z","etag":null,"topics":["auth","authentication","oauth","oauth2","vue","vuejs","vuejs2"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgrubelic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-30T14:50:36.000Z","updated_at":"2025-04-21T02:46:54.000Z","dependencies_parsed_at":"2024-06-18T12:38:51.804Z","dependency_job_id":"ff0ead59-9e82-4f2c-acdf-468d3b1d53b1","html_url":"https://github.com/dgrubelic/vue-authenticate","commit_stats":{"total_commits":104,"total_committers":6,"mean_commits":"17.333333333333332","dds":0.07692307692307687,"last_synced_commit":"f4aa8cb9a416842557213edaab19a30085b0a0aa"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgrubelic%2Fvue-authenticate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgrubelic%2Fvue-authenticate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgrubelic%2Fvue-authenticate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgrubelic%2Fvue-authenticate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgrubelic","download_url":"https://codeload.github.com/dgrubelic/vue-authenticate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252299553,"owners_count":21725722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","oauth","oauth2","vue","vuejs","vuejs2"],"created_at":"2024-08-01T09:00:33.668Z","updated_at":"2025-05-14T21:04:56.083Z","avatar_url":"https://github.com/dgrubelic.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","实用库","公用事业","Components \u0026 Libraries","Utilities","Utilities [🔝](#readme)"],"sub_categories":["国家管理","Utilities","State Management"],"readme":"[**WARNING**]: README file is currently in process of rewrite and will be released soon.\n\n# vue-authenticate\n\n[![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\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n**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.\n\n\n\nThe 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. \n\nFor 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).\n\n**WARNING:** From version 1.3.0 default request library is `axios` using `vue-axios` wrapper plugin.\n\nThis 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.\n\n## Supported OAuth providers and configurations\n\n1. Facebook (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L21)\n2. Google (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L34)\n3. Github (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L49)\n4. Instagram (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L61)\n5. Twitter (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L72)\n6. Bitbucket (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L81)\n7. LinkedIn (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L93)\n8. Microsoft Live (https://github.com/dgrubelic/vue-authenticate/blob/master/src/options.js#L106)\n\n## Installation\n```bash\nnpm install vue-authenticate\n```\n\n## Usage\n```javascript\nimport Vue from 'vue'\nimport VueAxios from 'vue-axios'\nimport VueAuthenticate from 'vue-authenticate'\nimport axios from 'axios';\n\nVue.use(VueAxios, axios)\nVue.use(VueAuthenticate, {\n  baseUrl: 'http://localhost:3000', // Your API domain\n  \n  providers: {\n    github: {\n      clientId: '',\n      redirectUri: 'http://localhost:8080/auth/callback' // Your client app URL\n    }\n  }\n})\n```\n\n### Email \u0026 password login and registration\n```javascript\nnew Vue({\n  methods: {\n    login: function () {\n      this.$auth.login({ email, password }).then(function () {\n        // Execute application logic after successful login\n      })\n    },\n\n    register: function () {\n      this.$auth.register({ name, email, password }).then(function () {\n        // Execute application logic after successful registration\n      })\n    }\n  }\n})\n```\n\n```html\n\u003cbutton @click=\"login()\"\u003eLogin\u003c/button\u003e\n\u003cbutton @click=\"register()\"\u003eRegister\u003c/button\u003e\n```\n\n### Social account authentication\n\n```javascript\nnew Vue({\n  methods: {\n    authenticate: function (provider) {\n      this.$auth.authenticate(provider).then(function () {\n        // Execute application logic after successful social authentication\n      })\n    }\n  }\n})\n```\n\n```html\n\u003cbutton @click=\"authenticate('github')\"\u003eauth Github\u003c/button\u003e\n\u003cbutton @click=\"authenticate('facebook')\"\u003eauth Facebook\u003c/button\u003e\n\u003cbutton @click=\"authenticate('google')\"\u003eauth Google\u003c/button\u003e\n\u003cbutton @click=\"authenticate('twitter')\"\u003eauth Twitter\u003c/button\u003e\n```\n\n### Vuex authentication\n\n#### Import and initialize all required libraries\n\n```javascript\n// ES6 example\nimport Vue from 'vue'\nimport Vuex from 'vuex'\nimport VueAxios from 'vue-axios'\nimport { VueAuthenticate } from 'vue-authenticate'\nimport axios from 'axios';\n\nVue.use(Vuex)\nVue.use(VueAxios, axios)\n\nconst vueAuth = new VueAuthenticate(Vue.prototype.$http, {\n  baseUrl: 'http://localhost:4000'\n})\n```\n\n```javascript\n// CommonJS example\nvar Vue = require('vue')\nvar Vuex = require('vuex')\nvar VueAxios = require('vue-axios')\nvar VueAuthenticate = require('vue-authenticate')\nvar axios = require('axios');\n\nVue.use(Vuex)\nVue.use(VueAxios, axios)\n\n// ES5, CommonJS example\nvar vueAuth = VueAuthenticate.factory(Vue.prototype.$http, {\n  baseUrl: 'http://localhost:4000'\n})\n```\n\nOnce you have created VueAuthenticate instance, you can use it in Vuex store like this:\n\n```javascript\nexport default new Vuex.Store({\n  \n  // You can use it as state property\n  state: {\n    isAuthenticated: false\n  },\n\n  // You can use it as a state getter function (probably the best solution)\n  getters: {\n    isAuthenticated () {\n      return vueAuth.isAuthenticated()\n    }\n  },\n\n  // Mutation for when you use it as state property\n  mutations: {\n    isAuthenticated (state, payload) {\n      state.isAuthenticated = payload.isAuthenticated\n    }\n  },\n\n  actions: {\n\n    // Perform VueAuthenticate login using Vuex actions\n    login (context, payload) {\n\n      vueAuth.login(payload.user, payload.requestOptions).then((response) =\u003e {\n        context.commit('isAuthenticated', {\n          isAuthenticated: vueAuth.isAuthenticated()\n        })\n      })\n\n    }\n  }\n})\n```\n\nLater in Vue component, you can dispatch Vuex state action like this\n\n```javascript\n// You define your store logic here\nimport store from './store.js'\n\nnew Vue({\n  store,\n\n  computed: {\n    isAuthenticated: function () {\n      return this.$store.getters.isAuthenticated()\n    }\n  },\n\n  methods: {\n    login () {\n      this.$store.dispatch('login', { user, requestOptions })\n    }\n  }\n})\n```\n\n### Custom request and response interceptors\n\nYou can easily setup custom request and response interceptors if you use different request handling library.\n\n**Important**: You must set both `request` and `response` interceptors at all times.\n\n```javascript\n\n/**\n* This is example for request and response interceptors for axios library\n*/\n\nVue.use(VueAuthenticate, {\n  bindRequestInterceptor: function () {\n    this.$http.interceptors.request.use((config) =\u003e {\n      if (this.isAuthenticated()) {\n        config.headers['Authorization'] = [\n          this.options.tokenType, this.getToken()\n        ].join(' ')\n      } else {\n        delete config.headers['Authorization']\n      }\n      return config\n    })\n  },\n\n  bindResponseInterceptor: function () {\n    this.$http.interceptors.response.use((response) =\u003e {\n      this.setToken(response)\n      return response\n    })\n  }\n})\n\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 Davor Grubelić\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgrubelic%2Fvue-authenticate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgrubelic%2Fvue-authenticate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgrubelic%2Fvue-authenticate/lists"}