我正在客户端实施identity server 4
。vue js
目前,我在应用程序中只有管理员登录名,密码和用户名。
我没有任何将用户重定向到登录的公共站点。我希望用户在点击应用程序客户端 URL 时直接重定向到登录页面。
目前在示例版本中identity server 4
,用户需要点击导航栏上的登录按钮并重定向到登录。
我想通过以下方式做:
- 客户端点击 URL。检查用户是否通过身份验证。
- 重定向到身份服务器。
- 使用用户名/密码登录
- 成功登录后重定向到客户端门户。
我很难将这种方法集成到vue js
.
在我当前的实现中,应用程序总是在循环中运行,并且总是被重定向到登录。
store.getters.isAuthenticated
永远不会是真的,它总是用 SignIn 重定向应用程序。
我无法弄清楚我是否遗漏了我router.beforeEach
的某些内容或oidc
.
路线:
export const routes = [
{
component: Full,
path: "/",
meta: {
requiresAuth: true
},
children: [
{
path: "/dashboard",
name: "Dahboard",
component: DashboardView,
meta: {
requiresAuth: true
}
},
{
path: "/signin",
component: Signin
},
{
path: "/company",
component: Company,
meta: {
requiresAuth: true
}
}
]
}
];
import Vue from "vue";
import VueRouter from "vue-router";
import { routes } from "./routes";
import store from '../store'
Vue.use(VueRouter);
let router = new VueRouter({
mode: "history",
routes
});
export default router;
router.beforeEach((to, from, next) => {
if (store.getters.isAuthenticated) {
const notValid = ['/signin', '/signup']
if (notValid.lastIndexOf(to.path) >= 0) {
next({
path: '/dashboard'
})
} else if (to.path === '/signout') {
store.commit('removeAuthentication')
next({
path: '/'
})
} else {
next()
}
} else if (to.matched.some(record => record.meta.requiresAuth)) {
next({
path: '/signin',
query: {
redirect: to.fullPath
}
})
} else if (to.path === '/signout') {
next({
path: '/'
})
} else {
next()
}
})
登录组件:
import authService from './authService';
export default {
name: 'Auth',
mounted() {
authService.login();
authService.completeLogin();
}
};
配置.js
export default {
authority: "https://localhost:44350",
client_id: "js",
redirect_uri: `${domain}/signin`,
response_type: "id_token token",
scope:"openid profile api1",
post_logout_redirect_uri : `${domain}`,
silent_redirect_uri: `${domain}/silent.html`,
}
登录:this.userManager.signinRedirect()
完成登录:this.userManager.signinRedirectCallback()
静音.html:
new Oidc.UserManager().signinSilentCallback()
.catch(function (error) {
console.error(error);
});