Angular 角度4+;Siteminder HTTP头问题
几周来,我一直在努力将Siteminder身份验证与我的nodejs/angular 4 web应用程序“集成” 在服务器端(节点),我有:Angular 角度4+;Siteminder HTTP头问题,angular,single-sign-on,siteminder,Angular,Single Sign On,Siteminder,几周来,我一直在努力将Siteminder身份验证与我的nodejs/angular 4 web应用程序“集成” 在服务器端(节点),我有: app.get('*',函数(req,res){ //读取Siteminder标题 如果(已验证){ res.sendFile(path.join(uu dirname,'dist/index.html'); }否则{ res.sendFile(path.join(_dirname,'dist/accessDenied.html'); }
app.get('*',函数(req,res){
//读取Siteminder标题
如果(已验证){
res.sendFile(path.join(uu dirname,'dist/index.html');
}否则{
res.sendFile(path.join(_dirname,'dist/accessDenied.html');
}
}
角形路由器处理其余部分
这适用于初始访问控制(检索数据的api和服务位于不同的机器上,这只是一个前端/客户端应用程序)
但是,现在用户需要角色,比如编辑/查看,我需要找到一种方法将这些角色从Siteminder头传递到angular前端以处理权限。
我玩过拦截器,但运气不好,似乎只处理angular应用程序中创建的请求。我还尝试了一些关于Siteminder/node/angular主题的相关问题的建议,但仍然运气不佳
我对node/angular非常陌生,感谢您的耐心和帮助。最后我自己找到了答案,在下面发布了详细信息,以防有人感兴趣。决定使用angular universal express引擎,如下所示 本质上,它允许Angular在服务器端运行,在服务器端可以访问请求头,然后可以将它们注入到客户端使用 在mymain.server.ts中:
app.engine('html', (_, options, callback) => {
let engine = ngExpressEngine({
bootstrap: ServerAppModule,
providers: [ { provide: 'headers', useFactory: () => options.req.headers } ]
});
engine(_, options, callback)
});
app.set('view engine', 'html');
app.set('views', 'dist');
app.use('/', express.static('dist', {index: false}));
ROUTES.forEach(route => {
app.get(route, (req, res) => {
console.log('Yaaay Siteminder headers:');
console.dir(req.headers);
res.render('index', {
req: req,
res: res
});
});
});
export class AppComponent implements OnInit {
constructor(private cache: TransferState, private injector: Injector, @Inject(PLATFORM_ID) private platformId: Object) {}
ngOnInit() {
if (isPlatformServer(this.platformId))
{
this.cache.set('user_role', this.injector.get('headers').sm_role);
}
}
}
然后在我的app.component.ts中:
app.engine('html', (_, options, callback) => {
let engine = ngExpressEngine({
bootstrap: ServerAppModule,
providers: [ { provide: 'headers', useFactory: () => options.req.headers } ]
});
engine(_, options, callback)
});
app.set('view engine', 'html');
app.set('views', 'dist');
app.use('/', express.static('dist', {index: false}));
ROUTES.forEach(route => {
app.get(route, (req, res) => {
console.log('Yaaay Siteminder headers:');
console.dir(req.headers);
res.render('index', {
req: req,
res: res
});
});
});
export class AppComponent implements OnInit {
constructor(private cache: TransferState, private injector: Injector, @Inject(PLATFORM_ID) private platformId: Object) {}
ngOnInit() {
if (isPlatformServer(this.platformId))
{
this.cache.set('user_role', this.injector.get('headers').sm_role);
}
}
}
之后,我可以在我的任何组件中注入私有缓存:TransferState
,并且可以在任何地方使用头,以便进行微调访问
等等