All Projects → dgrubelic → Vue Authenticate

dgrubelic / Vue Authenticate

Simple Vue.js authentication library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Authenticate

Fosite
Extensible security first OAuth 2.0 and OpenID Connect SDK for Go.
Stars: ✭ 1,738 (+28.74%)
Mutual labels:  authentication, oauth2, oauth, auth
React Aad
A React wrapper for Azure AD using the Microsoft Authentication Library (MSAL). The easiest way to integrate AzureAD with your React for authentication.
Stars: ✭ 324 (-76%)
Mutual labels:  authentication, oauth2, oauth
Grant
OAuth Proxy
Stars: ✭ 3,509 (+159.93%)
Mutual labels:  authentication, oauth2, oauth
Ueberauth
An Elixir Authentication System for Plug-based Web Applications
Stars: ✭ 1,259 (-6.74%)
Mutual labels:  authentication, oauth2, oauth
External Auth Server
easy auth for reverse proxies
Stars: ✭ 189 (-86%)
Mutual labels:  authentication, oauth2, oauth
Oauthlib
A generic, spec-compliant, thorough implementation of the OAuth request-signing logic
Stars: ✭ 2,323 (+72.07%)
Mutual labels:  authentication, oauth2, oauth
Angular Token
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
Stars: ✭ 376 (-72.15%)
Mutual labels:  authentication, oauth, auth
Oauth
🔗 OAuth 2.0 implementation for various providers in one place.
Stars: ✭ 336 (-75.11%)
Mutual labels:  authentication, oauth2, oauth
Doorkeeper
Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
Stars: ✭ 4,917 (+264.22%)
Mutual labels:  authentication, oauth2, oauth
Angular Auth Oidc Client
npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow
Stars: ✭ 577 (-57.26%)
Mutual labels:  authentication, oauth2, auth
Next Auth
Authentication for Next.js
Stars: ✭ 8,362 (+519.41%)
Mutual labels:  authentication, oauth2, oauth
Vuejs2 Authentication Tutorial
Stars: ✭ 144 (-89.33%)
Mutual labels:  authentication, auth, vuejs2
React Native Instagram Login
a react native instagram login component (support android & ios). Pull requests are welcome!
Stars: ✭ 139 (-89.7%)
Mutual labels:  authentication, oauth, auth
yii-auth-client
Yii Framework external authentication via OAuth and OpenID Extension
Stars: ✭ 20 (-98.52%)
Mutual labels:  oauth, oauth2, auth
Play Silhouette
Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, CAS, 2FA, TOTP, Credentials, Basic Authentication or custom authentication schemes.
Stars: ✭ 826 (-38.81%)
Mutual labels:  authentication, oauth2, oauth
Retroauth
A library build on top of retrofit, for simple handling of authenticated requests
Stars: ✭ 405 (-70%)
Mutual labels:  authentication, oauth2, oauth
Pizzly
The simplest, fastest way to integrate your app with an OAuth API 😋
Stars: ✭ 796 (-41.04%)
Mutual labels:  authentication, oauth2, oauth
Visa
Easy third party authentication (OAuth 2.0) for Flutter apps.
Stars: ✭ 50 (-96.3%)
Mutual labels:  authentication, oauth2, oauth
Httpie Oauth
OAuth plugin for HTTPie
Stars: ✭ 78 (-94.22%)
Mutual labels:  oauth, auth
Oauth2 Oidc Debugger
An OAuth2 and OpenID Connect Debugger
Stars: ✭ 78 (-94.22%)
Mutual labels:  authentication, oauth2

[WARNING]: README file is currently in process of rewrite and will be released soon.

vue-authenticate

Join the chat at https://gitter.im/vuejs-auth/vue-authenticate

vue-authenticate is easily configurable solution for Vue.js 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-axios. You will be able to use it with different libraries.

For now it is tested to work with vue-resource and axios (using vue-axios wrapper).

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 developed by Sahat Yalkabov. They share almost identical configuration and API so you can easily switch from Angular to Vue.js project.

Supported OAuth providers and configurations

  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)

Installation

npm install vue-authenticate

Usage

import Vue from 'vue'
import VueAxios from 'vue-axios'
import VueAuthenticate from 'vue-authenticate'
import axios from 'axios';

Vue.use(VueAxios, axios)
Vue.use(VueAuthenticate, {
  baseUrl: 'http://localhost:3000', // Your API domain
  
  providers: {
    github: {
      clientId: '',
      redirectUri: 'http://localhost:8080/auth/callback' // Your client app URL
    }
  }
})

Email & password login and registration

new Vue({
  methods: {
    login: function () {
      this.$auth.login({ email, password }).then(function () {
        // Execute application logic after successful login
      })
    },

    register: function () {
      this.$auth.register({ name, email, password }).then(function () {
        // Execute application logic after successful registration
      })
    }
  }
})
<button @click="login()">Login</button>
<button @click="register()">Register</button>

Social account authentication

new Vue({
  methods: {
    authenticate: function (provider) {
      this.$auth.authenticate(provider).then(function () {
        // Execute application logic after successful social authentication
      })
    }
  }
})
<button @click="authenticate('github')">auth Github</button>
<button @click="authenticate('facebook')">auth Facebook</button>
<button @click="authenticate('google')">auth Google</button>
<button @click="authenticate('twitter')">auth Twitter</button>

Vuex authentication

Import and initialize all required libraries

// ES6 example
import Vue from 'vue'
import Vuex from 'vuex'
import VueAxios from 'vue-axios'
import { VueAuthenticate } from 'vue-authenticate'
import axios from 'axios';

Vue.use(Vuex)
Vue.use(VueAxios, axios)

const vueAuth = new VueAuthenticate(Vue.prototype.$http, {
  baseUrl: 'http://localhost:4000'
})
// CommonJS example
var Vue = require('vue')
var Vuex = require('vuex')
var VueAxios = require('vue-axios')
var VueAuthenticate = require('vue-authenticate')
var axios = require('axios');

Vue.use(Vuex)
Vue.use(VueAxios, axios)

// ES5, CommonJS example
var vueAuth = VueAuthenticate.factory(Vue.prototype.$http, {
  baseUrl: 'http://localhost:4000'
})

Once you have created VueAuthenticate instance, you can use it in Vuex store like this:

export default new Vuex.Store({
  
  // You can use it as state property
  state: {
    isAuthenticated: false
  },

  // You can use it as a state getter function (probably the best solution)
  getters: {
    isAuthenticated () {
      return vueAuth.isAuthenticated()
    }
  },

  // Mutation for when you use it as state property
  mutations: {
    isAuthenticated (state, payload) {
      state.isAuthenticated = payload.isAuthenticated
    }
  },

  actions: {

    // Perform VueAuthenticate login using Vuex actions
    login (context, payload) {

      vueAuth.login(payload.user, payload.requestOptions).then((response) => {
        context.commit('isAuthenticated', {
          isAuthenticated: vueAuth.isAuthenticated()
        })
      })

    }
  }
})

Later in Vue component, you can dispatch Vuex state action like this

// You define your store logic here
import store from './store.js'

new Vue({
  store,

  computed: {
    isAuthenticated: function () {
      return this.$store.getters.isAuthenticated()
    }
  },

  methods: {
    login () {
      this.$store.dispatch('login', { user, requestOptions })
    }
  }
})

Custom request and response interceptors

You can easily setup custom request and response interceptors if you use different request handling library.

Important: You must set both request and response interceptors at all times.

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

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

  bindResponseInterceptor: function () {
    this.$http.interceptors.response.use((response) => {
      this.setToken(response)
      return response
    })
  }
})

License

The MIT License (MIT)

Copyright (c) 2017 Davor Grubelić

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].