[英]Cannot redirect back to angular client after login in identity server
在使用身份服務器登錄后,我遇到了重定向問題。
我有以下 angular-auth-oidc-client 配置:
export function configureAuth(oidcConfigService: OidcConfigService) {
return () =>
oidcConfigService.withConfig({
stsServer: 'http://localhost:5002',
redirectUrl: window.location.origin,
postLogoutRedirectUri: window.location.origin,
clientId: 'applications-portal',
scope: 'openid profile',
responseType: 'id_token token',
logLevel: LogLevel.Debug,
});
}
和 app.component.ts:
ngOnInit() {
this.oidcSecurityService.checkAuth().subscribe((auth) => {
console.log('is authenticated', auth);
if (!auth) {
this.login();
}
});
}
login() {
this.oidcSecurityService.authorize();
}
這是身份服務器應用程序中的客戶端配置:
new Client
{
ClientId = "applications-portal",
ClientName = "Applications Portal",
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes =
{
"service",
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
},
AccessTokenType = AccessTokenType.Jwt,
AllowAccessTokensViaBrowser = true,
RequireConsent = false,
RequireClientSecret = false,
RequirePkce = true,
RedirectUris = {
"http://localhost:4200",
},
PostLogoutRedirectUris =
{
"http://localhost:4200"
},
AllowedCorsOrigins =
{
"http://localhost:4200"
},
}
和 StartUp.cs:
services.ConfigureApplicationCookie(config =>
{
config.Cookie.Name = "Identity.Cookie";
config.LoginPath = "/Auth/Login";
});
問題是,當我在登錄(GET)方法中被重定向到 AuthController 時,我得到如下所示的 returnUrl: returnUrl Value
登錄后它不會將我重定向回客戶端應用程序,而是停留在登錄頁面上。 我相信 returnUrl 本身有問題。 我是第一次使用 IdentityServer,所以我真的不知道要挖掘什么。
更新:
問題出在 Chrome 瀏覽器中。 SameSite 的東西阻止它重定向。 我在這里嘗試了解決方案https://www.thinktecture.com/en/identity/samesite/prepare-your-identityserver/但它沒有用。 在其他瀏覽器中,它按預期工作。 你能給我一個提示,在這種情況下用 Chrome 做什么?
我也嘗試將其設置為 Lax,但沒有任何變化。
services.ConfigureApplicationCookie(config =>
{
config.Cookie.Name = "Identity.Cookie";
config.LoginPath = "/Auth/Login";
config.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
});
一種想法是,如果重定向 URL 應該是:
RedirectUris = {"http://localhost:4200/auth-callback"}.
該鏈接應指向 Angular 要將令牌發送到的 URL。
請參閱以下鏈接:
通過將 Cookie 配置更改為:
services.ConfigureApplicationCookie(config =>
{
config.Cookie.Name = "Identity.Cookie";
config.LoginPath = "/Auth/Login";
config.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
});
在配置方法中:
app.UseCookiePolicy(new CookiePolicyOptions
{
MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.Lax,
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.