【发布时间】:2022-02-11 20:25:08
【问题描述】:
这是我第一次尝试使用 OAuth。我正在使用 Angular 13 + angular-oauth2-oidc 库,我正在尝试配置代码流。我的问题是,在教程发现文档中默认使用,但我的身份验证服务器没有类似的东西,所以当在开始的应用程序中询问 identity_provider_url/.well-known/openid-configuration 时,我收到 404 错误。问题是如何在不从身份验证服务器加载发现文档的情况下配置代码流?
我只找到implicit flow 的没有发现文档的配置。
这就是我的代码现在的样子:
auth.config.ts
import { AuthConfig } from 'angular-oauth2-oidc';
export const authCodeFlowConfig: AuthConfig = {
// Url of the Identity Provider
issuer: '**************', // identity provider URL,
redirectUri: window.location.origin + '/index.html',
clientId: 'spa',
dummyClientSecret: 'secret',
responseType: 'code',
scope: 'read, write',
showDebugInformation: true,
};
app.component.ts
import {Component} from '@angular/core';
import {authCodeFlowConfig} from './sso.confiig';
import {OAuthService} from 'angular-oauth2-oidc';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'sso';
constructor(private oAuthService: OAuthService) {
this.oAuthService.configure(authCodeFlowConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin(); // I don`t want this
}
}
login.component.ts
import {Component, OnInit} from '@angular/core';
import {OAuthErrorEvent, OAuthService} from 'angular-oauth2-oidc';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
constructor(private oAuthService: OAuthService) {
this.oAuthService.events.subscribe(e => (e instanceof OAuthErrorEvent) ? console.error(e) : console.warn(e));
}
public async login(): Promise<void> {
await this.oAuthService.initCodeFlow();
}
public logout(): void {
this.oAuthService.logOut();
}
public get userName() {
let claims = this.oAuthService.getIdentityClaims();
if (!claims) return null;
return claims;
}
}
【问题讨论】:
-
你使用什么样的身份提供者?
-
@SaschaLeh 它基于github.com/doorkeeper-gem/doorkeeper/wiki/…
-
据我所知,“发现文档”是
OpenID Connect协议的一部分,doorkeeper只是实现了 OAuth2 标准。我认为您需要使用OpenID Connect扩展来扩展doorkeeper以使其工作。或使用Implicit Flowgithub.com/doorkeeper-gem/doorkeeper-openid_connect -
@SaschaLeh 链接的 GitHub 存储库确实谈到了支持“授权代码”流程?不确定是否也支持 PKCE?
-
OP,您确定知名端点不在您的 IDS 中吗? Doorkeeper repo has routes for the discovery document 好像是? - 无论哪种方式,您都可以go through the relevant Angular code 查看您可以配置的确切字段,并选择与您的情况相关的字段。
标签: angular oauth-2.0 oauth angular-oauth2-oidc