【问题标题】:Azure AD with Angular 4带有 Angular 4 的 Azure AD
【发布时间】:2018-01-01 00:19:36
【问题描述】:

我正在使用带有 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' }

我似乎无法配置从 url 获取 id_token 的路由,因此我可以使用它来授权其他请求。如何从重定向中取回这个 id_token?

【问题讨论】:

  • 你是在问如何从activatedRoute获取片段?
  • 这可以工作,但我的路线缺少登录路线并重定向到家。
  • 嗨 Darthg8r,您在 angular4 中使用什么包来连接 AAD?我尝试使用 ng2-adal,但遇到 Angular 4.4.3 的“找不到模块”问题。

标签: angular azure-active-directory openid-connect


【解决方案1】:

在组件 StarterViewComponent 中,实现接口 OnInit 并将其写入方法 ngOnInit。

export class StarterViewComponent implements OnInit  {

    ngOnInit() {

      if (window.location.hash) {
            this.someLoginService.validateToken(window.location.hash);
        }
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-10
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2014-11-02
    • 1970-01-01
    相关资源
    最近更新 更多