我对adal.js有问题。
在我的应用程序的第一次加载中,当它没有令牌时,adal将重新加载Hole项目3次,因此我重复了所有我的http请求。香港专业教育学院尝试了几个修复程序,但没有一个工作。 我正在使用Angular 5.2.1。
我可以在其中之一中看到重新加载网址:id_token。
有人有同样的问题吗?我所有的合作伙伴都在为此工作,但没有解决方案...
我有此代码:
index.html
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8">
<title>Santander Global Tech</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400" rel="stylesheet">
<link rel="preconnect" href="https://graph.microsoft.com" crossorigin/>
<link rel="preconnect" href="https://santandernet.sharepoint.com" crossorigin/>
<link rel="preconnect" href="https://login.microsoftonline.com" crossorigin/>
<link rel="preconnect" href="https://www.google-analytics.com/" crossorigin/>
<link rel="icon" type="image/x-icon" href="favicon.ico" >
<link href="/assets/chatbot/css/botchat.css" rel="stylesheet" />
<link href="/assets/chatbot/css/SamChatBot.web.css" rel="stylesheet" />
<script src="/assets/lib/adal.min.js"></script>
<script src="/assets/chatbot/js/SamChatBotWeb.js"></script>
<script src="/assets/chatbot/js/botchatweb.js"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
app-routing.module.ts
const routes: Routes = [
{ path: '', component: OutletComponent, canActivate:
[ConfigGuardService],
children: [
{ path: '', component: HomeComponent, canActivate: [AuthUserGuard, AuthGuard ],
children: [
{ path: '', component: DashboardComponent, pathMatch: 'full' },
{ path: 'detalle-noticia/:id', component: NoticeDetailsComponent },
{ path: 'area-comunicacion', loadChildren: './comunication-area/comunication-area.module#ComunicationAreaModule'},
{ path: 'resultados/:string', loadChildren: './search-result/search-result.module#SearchResultModule'},
{ path: 'resultados/detalle-perfil/:persona', loadChildren: './profiles/profiles.module#ProfilesModule'},
{ path: 'herramientas', loadChildren: './tools/tools.module#ToolsModule'},
{ path: 'solicitudes', loadChildren: './allrequests/allrequests.module#AllrequestsModule'},
{ path: '**', redirectTo: ''},
]},
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule],
providers: [
ConfigGuardService,
AuthUserGuard
]
})
auth.guard.ts
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
this.adalSrv.context.handleWindowCallback();
if (this.adalSrv.isLogged) {
return true;
} else {
this.adalSrv.context.login();
// Este es el navigate que tiene que funcionar. Tiene que ir al componente "login" pero se queda en bucle y no va al login.
// Creemos que es por algo del app-routing.module y dónde colocar el componente "login" en la estructura de los path y los children.
// this.router.navigate(['login'], { queryParams: { returnUrl: state.url } });
console.log('Logando');
return false;
}
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(childRoute, state);
}
}