【问题标题】:angular-oidc library code flow without discovery document没有发现文档的 angular-oidc 库代码流
【发布时间】:2022-03-19 07:09:37
【问题描述】:

我们必须在 Angular 应用程序中实现 oauth2 代码流。到目前为止,我们一直使用 implicit flow 没有任何问题,我们正在使用这个库 https://github.com/manfredsteyer/angular-oauth2-oidc。现在,对于代码流程,我们没有任何可用的发现文档,因此库无法继续流程。是否有可能手动配置代码流的 URL?我们使用的是 8.0.4 版本的库,我们的 Angular 版本是 7。

谢谢!

【问题讨论】:

  • 也有这个问题
  • @JoãoPedroSáMedeiro 这个问题你解决了吗?

标签: oauth-2.0 angular7 angular-oauth2-oidc


【解决方案1】:

授权代码传统流程(无 pkce)手动配置,无需发现文档 - manfredsteyer / angular-oauth2-oidc。

他们在https://github.com/manfredsteyer/angular-oauth2-oidc/issues/1051 上发布了解决方案。

来自 jeroenheijmans

的一些细节

*这是可能的,但是您需要手动配置所有内容。 跳过 loadDiscoveryDocument... 部分,而是配置 那个地方的所有东西,然后像往常一样继续 会的。

在 #1051 中,我认为提出了同样的问题 - https://github.com/manfredsteyer/angular-oauth2-oidc/issues/1051*

根据我的示例,您可以大致执行以下操作:

private configureWithoutDisovery(): Promise<void> {
    // configure the library here, by hand, per your IDS settings
}

public runInitialLoginSequence(): Promise<void> {
    return this.configureWithoutDisovery()
      .then(() => this.oauthService.tryLogin())
      .then(() => {
        if (this.oauthService.hasValidAccessToken()) {
          return Promise.resolve();
        }
        return this.oauthService.silentRefresh()
          .then(() => Promise.resolve())
          .catch(result => {
            const errorResponsesRequiringUserInteraction = [ 'interaction_required', 'login_required', 'account_selection_required', 'consent_required' ];

            if (result && result.reason && errorResponsesRequiringUserInteraction.indexOf(result.reason.error) >= 0) {
              console.warn('User interaction is needed to log in, we will wait for the user to manually log in.');
              return Promise.resolve();
            }
            return Promise.reject(result);
          });
      })

      .then(() => {
        this.isDoneLoadingSubject$.next(true);
        // optionally use this.oauthService.state to route to original location
      })
      .catch(() => this.isDoneLoadingSubject$.next(true));
  }

【讨论】:

    猜你喜欢
    • 2021-01-29
    • 2022-07-07
    • 2018-04-11
    • 2020-03-03
    • 2021-05-12
    • 2020-06-06
    • 2020-10-15
    • 2021-07-13
    • 2020-01-13
    相关资源
    最近更新 更多