问题描述
我使用 MsAdalAngular6Module 库来保护我的应用程序。 (微软-adal-angular6) 在 Azure 中,我向我的应用程序添加了两个不同的角色。我的应用程序应该知道登录用户具有哪个角色。有管理员角色和员工角色。我想为员工锁定删除和发布请求。
我的代码:
component.ts
import { Component } from '@angular/core';
import { MsAdalAngular6Service } from 'microsoft-adal-angular6';
import { Observable } from 'rxjs';
@Component({
selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'angular-client';
accesstoken: string;
constructor(private adalService: MsAdalAngular6Service) {
}
login(): void {
this.adalService.login();
}
logout(): void {
this.adalService.logout();
}
getLoggedInUser(): any {
return this.adalService.LoggedInUserName;
}
getAccesstoken(): Observable<any> {
return this.adalService.acquiretoken('backend-api-uri');
}
getToken(): string {
return this.adalService.accesstoken;
}
get isUserLoggedIn(){
let claims:any = this.adalService.isAuthenticated;
return claims ? claims : null;
}
}
module.ts
import { browserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MsAdalAngular6Module } from 'microsoft-adal-angular6';
@NgModule({
declarations: [
AppComponent
],imports: [
browserModule,AppRoutingModule,MsAdalAngular6Module.forRoot({
tenant: 'my tentant id',clientId: 'my client id',redirectUri: 'http://localhost:4200',scope: '',appRoles:
[
{
allowedMemberTypes: [
"User"
],description: "Admins have the ability to create and add Configurators.",displayName: "Admin",id: "My role ID",isEnabled: true,lang: null,origin: "Application",value: "SalesPage.AdminRole"
}
],availabletoOtherTenants: false,endpoints: {
'api application url': 'api application client id',// this is for fetching the access token
},navigatetoLoginRequestUrl: false,cacheLocation: '<localStorage / sessionStorage>',postlogoutRedirectUri: 'http://localhost:4200',}),],providers: [],bootstrap: [AppComponent]
})
export class AppModule { }
有人对如何做到这一点有建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)