vue-identity
is a vue plugin that uses jwt to make authentication easy.
$ npm install vue-identity
import VueIdentity from 'vue-identity'
Vue.use(VueIdentity, {
url: "/auth", // full url to your auth endpoint
})
This will ask the server for an accessToken
by passing it a refreshToken
. Cookies are sent with this request if you prefer.
this.$identity.authenticate().then(function(){ console.log( "Logged in!" ) })
Request a new accessToken
and refreshToken
by passing credentials to the server. Credentials are sent as parameters of login and are POST
ed to the server.
this.$identity.login({username: "salty",password:"quark"}).then(function(){ console.log( "Logged in!" ) })
In your html, you can access the user
state
<div v-if="$identity.user">
<p>Hello {{$identity.user.name}}</p>
</div>
After authenticating, an interceptor is added to vue-resource
that sends the accessToken
in the Authorization
header as a Bearer token.