Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@simbachain/vue-authenticate
Advanced tools
[WARNING]: README file is currently in process of rewrite and will be released soon.
Fork of vue-authenticate adding support for refresh tokens and PKCE auth code flow.
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.
npm install vue-authenticate
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
}
}
})
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>
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>
// 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 })
}
}
})
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
})
}
})
You can use this library on the server side without problems by following the steps below.
storageType:' cookieStorage'
.VueAuthenticate.factory()
Here an example with plugins of !UVue
Axios Plugin:
import axios from 'axios';
import cookies from 'js-cookie'; // only browser
/**
* This plugin create an axios HTTP client to do request.
*/
export default {
async beforeCreate(context, inject) {
// Create axios client
const httpClient = axios.create({
// Change API url: depends on server side or client side
baseURL: '/api/v1',
});
// Inject httpClient eveywhere
inject('http', httpClient);
inject('axios', httpClient);
// You can use it everywhere in your app:
// - In UVue context: `context.$http.get(...)`
// - In your components: `this.$http.get(...)`
// - In your store actions: `this.$http.get(...)`
},
};
VueAuthenticate Plugin
import VueAuthenticate from 'vue-authenticate/dist/vue-authenticate';
const vueAuthenticateConfig = {
// ...
tokenPrefix: undefined,
tokenName: 'token',
storageType: 'cookieStorage', // Important.
// ...
};
export default {
async beforeCreate(context, inject) {
let vueAuthInstance;
if (process.client) { // browser
vueAuthInstance = VueAuthenticate.factory(context.$http, vueAuthenticateConfig);
} else { // server
const vueConfig = { ...vueAuthenticateConfig, storageType: 'memoryStorage' }; // Override with memory storage
const { tokenName } = vueConfig; // get the token name
const accessToken = context.req.cookies[tokenName]; // Get the access token from request
vueAuthInstance = VueAuthenticate.factory(context.$http, vueConfig);
vueAuthInstance.storage.setItem(tokenName, accessToken); // set the current access token
}
inject('auth', vueAuthInstance); // Inject auth eveywhere
// You can use it everywhere in your app:
// - In UVue context: `context.$auth.isAuthenticated(...)`
// - In your components: `this.$auth.isAuthenticated(...)`
// - In your store actions: `this.$auth.isAuthenticated(...)`
},
};
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.
FAQs
Authentication library for Vue.js
The npm package @simbachain/vue-authenticate receives a total of 1 weekly downloads. As such, @simbachain/vue-authenticate popularity was classified as not popular.
We found that @simbachain/vue-authenticate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.