我刚接触Aurelia,所以我的问题是在多用户环境中使用Aurelia的指导原则是什么。使用角色授权的Windows身份验证?有没有可能用asp mvc作为主机的示例代码?
发布于 2016-05-07 00:05:33
下面是一个简单的授权工作流程示例:
应用程序结构:
/src
main.js
-app
-app.html -- app root component for logged users
-app.js -- app root component for logged users
-nav-bar.html
-nav-bar.js
-login
-login.js -- app root component for unlogged users
-login.html -- app root component for unlogged users
-user-password.html -- route with user/password fields.
-user-password.js -- route with user/password fields.
-forgot-password.html
-forgot-password.jsMAIN.JS:
export function(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
//initialise
aurelia.start().then(a => {
let rootComponent = isLoggedIn() ? 'app/app' : 'login/login';
a.setRoot(rootComponent, document.body);
});
});
function isLoggedIn() {
//do your magic here
//check if the current user has a valid authorisation token
}APP.HTML:
<template>
<!-- THIS IS WHERE YOU APP WILL BE RENDERED (if the user is logged) -->
<nav-bar></nav-bar>
<router-view></router-view>
</template>LOGIN.HTML:
<template>
<!-- THIS IS WHERE YOU APP WILL BE RENDERED (if the user is not logged) -->
<router-view></router-view>
</template>LOGIN.JS:
export class Login {
configureRouter(config, router) {
config.map([
{ route: '', name: 'user-password', moduleId: './user-password', title: 'Sign In' },
{ route: 'forgot-password', name: 'forgot-password', moduleId: './forgot-password', title: 'Forgot Password?' }
]);
config.mapUnknownRoutes(instruction => {
//check instruction.fragment
return './user-password';
});
this.router = router;
}
}USER-PASSWORD.HTML
<template>
<input type="text">
<input type="password">
<button type="submit"></button>
</template>USER-PASSWORD.JS
export class UserPassword {
login() {
//check if the user and password are valid
//redirect to the app root component
//import and inject { Aurelia } from 'aurelia-framework';
this.aurelia.setRoot('app/app');
}
}如果有什么不够清楚,尽管问我!
希望这能有所帮助!
发布于 2017-07-28 00:46:48
有一个同构的授权库,称为CASL。您可以在medium https://medium.com/@sergiy.stotskiy/casl-based-authorization-in-aurelia-app-3e44c0fe1703上的Aurelia应用程序中了解到它的集成
发布于 2017-11-01 15:42:43
我编写了一个库CASL来处理JavaScript中的授权逻辑。你也可以在我的github和related article on Medium上找到a sample application of integration CASL and Aurelia。
希望这能对你有所帮助!
https://stackoverflow.com/questions/37076484
复制相似问题