首页 文章

Azure AD与Angular 4

提问于
浏览
1

我正在使用带有Angular 4应用程序的隐式流的Azure AD . 我的NG4应用程序使用PathLocationStrategy进行路由,以便它可以利用干净的URL . 我的AAD身份验证请求如下所示:

https://login.microsoftonline.com/xxxxx/oauth2/authorize?client_id=xxxx&response_type=id_token&redirect_uri=http://localhost:4200/login&response_mode=fragment&scope=openid&state=12345&nonce=xxxx

授权通过,我被重定向到http://localhost:4200/login#id_token=xxxxx,然后被重定向到http://localhost:4200/home#id_token=xxxxx

我的路线看起来像这样:

{ path: '', redirectTo: 'home', pathMatch: 'full' },
  {
    path: '', component: BlankLayoutComponent,
    children: [
      { path: 'login#id_token=:id_token', component: LoginComponent }
    ]
  },
  {
    path: '', component: BasicLayoutComponent,
    children: [
      { path: 'home', component: StarterViewComponent }
    ]
  },
  // Handle all other routes
  { path: '**', redirectTo: 'home' }

我似乎无法获得配置的路由,从网址中获取id_token,以便我可以使用它来授权其他请求 . 如何从重定向中恢复此id_token?

1 回答

  • 0

    在组件 StarterViewComponent 中,实现接口 OnInit 并在方法ngOnInit中写入它 .

    export class StarterViewComponent implements OnInit  {
    
        ngOnInit() {
    
          if (window.location.hash) {
                this.someLoginService.validateToken(window.location.hash);
            }
        }
    
    }
    

相关问题