This commit is contained in:
@@ -1,24 +1,74 @@
|
|||||||
|
/*eslint-disable*/
|
||||||
import ayconfig from "../utils/config";
|
import ayconfig from "../utils/config";
|
||||||
|
|
||||||
|
function status(response) {
|
||||||
|
if (response.status >= 200 && response.status < 300) {
|
||||||
|
return Promise.resolve(response);
|
||||||
|
} else {
|
||||||
|
return Promise.reject(new Error(response.statusText));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function json(response) {
|
||||||
|
var v = response.json();
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
authenticate(login, password) {
|
authenticate(login, password, cb) {
|
||||||
fetch(ayconfig.apiUrl + "/auth", {
|
fetch(ayconfig.apiUrl + "auth", {
|
||||||
login: login,
|
method: "post",
|
||||||
password: password
|
mode: "cors",
|
||||||
})
|
headers: {
|
||||||
.then(function(response) {
|
Accept: "application/json, text/plain, */*",
|
||||||
if (response.status != 200) {
|
"Content-Type": "application/json"
|
||||||
alert("Error: " + response.statusText);
|
},
|
||||||
return;
|
body: JSON.stringify({
|
||||||
}
|
login: login,
|
||||||
// Handle response you get from the server
|
password: password
|
||||||
response.json().then(function(data) {
|
|
||||||
//set token in config here
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
})
|
||||||
alert("Fetch Error :-S", err);
|
.then(status)
|
||||||
|
.then(json)
|
||||||
|
.then(function(data) {
|
||||||
|
console.log(
|
||||||
|
"AUTH.JS::authenticate() -> Request succeeded with JSON response",
|
||||||
|
data
|
||||||
|
);
|
||||||
|
cb(data);
|
||||||
|
//return data;
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log("Request failed", error);
|
||||||
|
cb(error); //sb cb(data,error or something)
|
||||||
|
//return error;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async authenticatepromise(login, password) {
|
||||||
|
return fetch(ayconfig.apiUrl + "auth", {
|
||||||
|
method: "post",
|
||||||
|
mode: "cors",
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json, text/plain, */*",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
login: login,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(status)
|
||||||
|
.then(json)
|
||||||
|
.then(function(data) {
|
||||||
|
console.log(
|
||||||
|
"AUTH.JS::authenticatepromise() -> Request succeeded with JSON response",
|
||||||
|
data
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log("Request failed", error);
|
||||||
|
return error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import Router from "vue-router";
|
import Router from "vue-router";
|
||||||
import Home from "./views/Home.vue";
|
import Home from "./views/Home.vue";
|
||||||
import { isLoggedIn, login, logout } from './utils/auth';
|
//import { isLoggedIn, login, logout } from "./utils/auth";
|
||||||
|
|
||||||
Vue.use(Router);
|
Vue.use(Router);
|
||||||
|
|
||||||
@@ -9,30 +9,30 @@ export default new Router({
|
|||||||
mode: "history",
|
mode: "history",
|
||||||
base: process.env.BASE_URL,
|
base: process.env.BASE_URL,
|
||||||
routes: [
|
routes: [
|
||||||
{
|
// {
|
||||||
path: "/",
|
// path: "/",
|
||||||
redirect: {
|
// redirect: {
|
||||||
name: "login"
|
// name: "login"
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
path: "/login",
|
path: "/login",
|
||||||
name: "login",
|
name: "login",
|
||||||
component: () =>
|
component: () =>
|
||||||
import(/* webpackChunkName: "login" */ "./views/login.vue")
|
import(/* webpackChunkName: "login" */ "./views/login.vue")
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/secure",
|
|
||||||
name: "secure",
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "secure" */ "./views/secure.vue")
|
|
||||||
},
|
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// path: "/",
|
// path: "/secure",
|
||||||
// name: "home",
|
// name: "secure",
|
||||||
// component: Home
|
// component: () =>
|
||||||
|
// import(/* webpackChunkName: "secure" */ "./views/secure.vue")
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
name: "home",
|
||||||
|
component: Home
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/about",
|
path: "/about",
|
||||||
name: "about",
|
name: "about",
|
||||||
@@ -45,34 +45,34 @@ export default new Router({
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
// Router.beforeEach((to, from, next) => {
|
||||||
if(to.matched.some(record => record.meta.requiresAuth)) {
|
// if(to.matched.some(record => record.meta.requiresAuth)) {
|
||||||
if (localStorage.getItem('jwt') == null) {
|
// if (localStorage.getItem('jwt') == null) {
|
||||||
next({
|
// next({
|
||||||
path: '/login',
|
// path: '/login',
|
||||||
params: { nextUrl: to.fullPath }
|
// params: { nextUrl: to.fullPath }
|
||||||
})
|
// })
|
||||||
} else {
|
// } else {
|
||||||
let user = JSON.parse(localStorage.getItem('user'))
|
// let user = JSON.parse(localStorage.getItem('user'))
|
||||||
if(to.matched.some(record => record.meta.is_admin)) {
|
// if(to.matched.some(record => record.meta.is_admin)) {
|
||||||
if(user.is_admin == 1){
|
// if(user.is_admin == 1){
|
||||||
next()
|
// next()
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
next({ name: 'userboard'})
|
// next({ name: 'userboard'})
|
||||||
}
|
// }
|
||||||
}else {
|
// }else {
|
||||||
next()
|
// next()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else if(to.matched.some(record => record.meta.guest)) {
|
// } else if(to.matched.some(record => record.meta.guest)) {
|
||||||
if(localStorage.getItem('jwt') == null){
|
// if(localStorage.getItem('jwt') == null){
|
||||||
next()
|
// next()
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
next({ name: 'userboard'})
|
// next({ name: 'userboard'})
|
||||||
}
|
// }
|
||||||
}else {
|
// }else {
|
||||||
next()
|
// next()
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
|
|||||||
@@ -3,20 +3,6 @@ import decode from "jwt-decode";
|
|||||||
//import auth0 from 'auth0-js';
|
//import auth0 from 'auth0-js';
|
||||||
//import Router from 'vue-router';
|
//import Router from 'vue-router';
|
||||||
//import Auth0Lock from 'auth0-lock';
|
//import Auth0Lock from 'auth0-lock';
|
||||||
const ID_TOKEN_KEY = "id_token";
|
|
||||||
const ACCESS_TOKEN_KEY = "access_token";
|
|
||||||
const USER_ROLES = AuthorizationRoles.NoRole;
|
|
||||||
|
|
||||||
// const CLIENT_ID = '{AUTH0_CLIENT_ID}';
|
|
||||||
// const CLIENT_DOMAIN = '{AUTH0_DOMAIN}';
|
|
||||||
// const REDIRECT = 'YOUR_CALLBACK_URL';
|
|
||||||
// const SCOPE = '{SCOPE}';
|
|
||||||
// const AUDIENCE = 'AUDIENCE_ATTRIBUTE';
|
|
||||||
|
|
||||||
// var auth = new auth0.WebAuth({
|
|
||||||
// clientID: CLIENT_ID,
|
|
||||||
// domain: CLIENT_DOMAIN
|
|
||||||
// });
|
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/15551652/javascript-enum-flag-check
|
//https://stackoverflow.com/questions/15551652/javascript-enum-flag-check
|
||||||
const AuthorizationRoles = {
|
const AuthorizationRoles = {
|
||||||
@@ -54,6 +40,21 @@ const AuthorizationRoles = {
|
|||||||
OpsAdminFull: 16384
|
OpsAdminFull: 16384
|
||||||
}; //end AuthorizationRoles
|
}; //end AuthorizationRoles
|
||||||
|
|
||||||
|
const ID_TOKEN_KEY = "id_token";
|
||||||
|
const ACCESS_TOKEN_KEY = "access_token";
|
||||||
|
const USER_ROLES = AuthorizationRoles.NoRole;
|
||||||
|
|
||||||
|
// const CLIENT_ID = '{AUTH0_CLIENT_ID}';
|
||||||
|
// const CLIENT_DOMAIN = '{AUTH0_DOMAIN}';
|
||||||
|
// const REDIRECT = 'YOUR_CALLBACK_URL';
|
||||||
|
// const SCOPE = '{SCOPE}';
|
||||||
|
// const AUDIENCE = 'AUDIENCE_ATTRIBUTE';
|
||||||
|
|
||||||
|
// var auth = new auth0.WebAuth({
|
||||||
|
// clientID: CLIENT_ID,
|
||||||
|
// domain: CLIENT_DOMAIN
|
||||||
|
// });
|
||||||
|
|
||||||
export function login() {
|
export function login() {
|
||||||
// auth.authorize({
|
// auth.authorize({
|
||||||
// responseType: 'token id_token',
|
// responseType: 'token id_token',
|
||||||
@@ -149,4 +150,4 @@ export function hasRole(role) {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Auth JWT needs to return roles as an int enum
|
//TODO: Auth JWT needs to return roles as an int enum
|
||||||
|
|||||||
@@ -22,23 +22,34 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
login() {
|
login() {
|
||||||
if (this.input.username != "" && this.input.password != "") {
|
if (this.input.username != "" && this.input.password != "") {
|
||||||
// eslint-disable-next-line
|
auth.authenticate(this.input.username, this.input.password, function(
|
||||||
var response = auth.authenticate(
|
data
|
||||||
this.input.username,
|
|
||||||
this.input.password
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.input.username == this.$store.state.mockAccount.username &&
|
|
||||||
this.input.password == this.$store.state.mockAccount.password
|
|
||||||
) {
|
) {
|
||||||
this.$emit("authenticated", true);
|
// eslint-disable-next-line
|
||||||
this.$router.replace({ name: "secure" });
|
console.log("LOGIN.VUE::login() -> CB VERSION DATA:", data);
|
||||||
} else {
|
});
|
||||||
alert("The username and / or password is incorrect");
|
|
||||||
}
|
// if (
|
||||||
} else {
|
// this.input.username == this.$store.state.mockAccount.username &&
|
||||||
alert("A username and password must be present");
|
// this.input.password == this.$store.state.mockAccount.password
|
||||||
|
// ) {
|
||||||
|
// this.$emit("authenticated", true);
|
||||||
|
// this.$router.replace({ name: "secure" });
|
||||||
|
// } else {
|
||||||
|
// alert("The username and / or password is incorrect");
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// alert("A username and password must be present");
|
||||||
|
|
||||||
|
auth
|
||||||
|
.authenticatepromise(this.input.username, this.input.password)
|
||||||
|
.then(response => {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(
|
||||||
|
"LOGIN.VUE::login() -> PROMISE VERSION RESPONSE:",
|
||||||
|
response
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,18 @@ namespace AyaNova
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Add service and create Policy with options
|
||||||
|
_log.LogDebug("BOOT: init CORS service");
|
||||||
|
services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("CorsPolicy",
|
||||||
|
builder => builder.AllowAnyOrigin()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowCredentials());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
_log.LogDebug("BOOT: init MVC service");
|
_log.LogDebug("BOOT: init MVC service");
|
||||||
_log.LogDebug("BOOT: init Metrics service");
|
_log.LogDebug("BOOT: init Metrics service");
|
||||||
|
|
||||||
@@ -240,7 +252,7 @@ namespace AyaNova
|
|||||||
|
|
||||||
// Token will only be valid if not expired yet, with 5 minutes clock skew.
|
// Token will only be valid if not expired yet, with 5 minutes clock skew.
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
RequireExpirationTime = true,
|
RequireExpirationTime = true,
|
||||||
ClockSkew = new TimeSpan(0, 5, 0),
|
ClockSkew = new TimeSpan(0, 5, 0),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -357,6 +369,8 @@ namespace AyaNova
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
_log.LogDebug("BOOT: pipeline - CORS");
|
||||||
|
app.UseCors("CorsPolicy");
|
||||||
|
|
||||||
//USE MVC
|
//USE MVC
|
||||||
_log.LogDebug("BOOT: pipeline - MVC");
|
_log.LogDebug("BOOT: pipeline - MVC");
|
||||||
|
|||||||
Reference in New Issue
Block a user