【发布时间】:2022-01-10 01:27:54
【问题描述】:
我正在尝试将 Auth0 添加到我的 Angular 应用程序(我在 VS2022 中使用 .NET Core Angular 项目模板)。
- .NET 6
- 角度:13.0.2
- @auth0/auth0-angular: 1.8.0
首先,我关注https://auth0.com/docs/quickstart/spa/angular/01-login,但登录后 Auth0 使用“代码”和“状态”查询参数将我重定向回我的站点(本地主机)。 我找到了 handleRedirectCallback() 方法并调用它。但我收到一个错误:
Auth0 代码足够小:
AuthModule.forRoot({
domain: environment.auth0.domain,
clientId: environment.auth0.clientId,
redirectUri: environment.auth0.redirectUrl
})
export class LoginComponent {
constructor(auth: AuthService) {
if (window.location.href.indexOf('state=') > -1) {
auth.handleRedirectCallback().subscribe(value => {
debugger;
});
} else {
auth.loginWithRedirect();
}
}
}
我还创建了一个新的默认 Angular 项目并添加了代码,但我仍然看到 Invalid state 错误。
【问题讨论】: