Vue ASP.NET OWIN Authentication Plugin

1.5.4 · abandoned · verified Wed Apr 22

Vue-aspnet-auth is a Vue.js plugin designed to integrate authentication with ASP.NET OWIN MVC backends. It acts as a wrapper around the `aspnet-auth` library, providing a convenient way to manage user login, logout, and token handling within a Vue application. The package is currently at version 1.5.4, released in May 2019. Its release cadence was inconsistent even during its active period, and it appears to be abandoned, with no significant updates or commits since 2019. Key differentiators include its specific focus on OWIN-based ASP.NET authentication, which distinguishes it from more generic JWT or OAuth client libraries, though this also ties it to an older backend technology stack. Due to its abandonment, it is not suitable for new projects and may pose security risks or compatibility challenges with modern Vue or JavaScript environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install and initialize the `vue-aspnet-auth` plugin, then use its `$auth` instance for user login within a basic Vue component. It also shows how to dynamically set the base URL for API requests and handles potential login errors.

import Vue from 'vue';
import { AspnetAuth } from 'vue-aspnet-auth';

Vue.use(AspnetAuth, {
  url: 'http://localhost:46993' // Replace with your ASP.NET backend URL
});

// Example Vue component demonstrating login
export default {
  name: 'login-component',
  data() {
    return {
      username: '',
      password: '',
      error: null
    };
  },
  methods: {
    login() {
      this.$auth.login(this.username, this.password, (data) => {
        if (data.result) {
          console.log('Login successful:', this.$auth.authentication);
          // Example: Redirect or update store
          // this.$store.commit('auth', this.$auth.authentication);
          // this.$root.$emit('app.loggedin');
        } else {
          this.error = data.message || 'Login failed.';
          console.error('Login failed:', this.error);
        }
      });
    },
    logout() {
      this.$auth.logout();
      console.log('Logged out.');
    }
  },
  created() {
    // Can dynamically update the URL if needed, though better set during Vue.use()
    // this.$auth.url = `http://localhost:1234`; 
    console.log('Auth plugin initialized. Current URL:', this.$auth.url);
  },
  template: `
    <div>
      <h2>Login</h2>
      <form @submit.prevent="login">
        <input type="text" v-model="username" placeholder="Username" />
        <input type="password" v-model="password" placeholder="Password" />
        <button type="submit">Login</button>
      </form>
      <p v-if="error" style="color: red;">{{ error }}</p>
      <button @click="logout">Logout</button>
    </div>
  `
};

view raw JSON →