У меня есть приложение Angular, интегрированное с Identity Server 4. Я не могу реализовать выход из системы.Я звоню signoutRedirect
Я заметил, что вызывается connect / endSession с id_token_hint
и postlogoutredirecturi
.
В режиме отладки вызывается функция выхода из системы AccountController
, но User
не проходит проверку подлинности.
Если я использую тот же запрос endSession
и запускаю его, либо запускаю из браузера, он работает, и файлы cookie удаляются
Конфигурация моего сервера
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients())
.AddProfileService<UserProfileService>();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies");
.AddOpenIdConnect("oidc", "OpenID Connect", options =>
{
options.SignInScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Authority = "https://demo.identityserver.io/";
//options.Authority = "https://localhost:5000/";
options.ClientId = "mvc";
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
};
});
//Allow CORS
services.AddCors();
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info {
Title = "RegalPay IDP Service",
Version = "v1",
Description = "A RegalPay IDP service web API",
TermsOfService = "None",
Contact = new Contact
{
Name = "Regal Software",
Email = string.Empty,
Url = "https://regal-software.com/"
},
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.OperationFilter<AddAuthorizationHeader>();
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors(builder =>
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
);
app.UseCors("AllowAll");
app.UseHttpsRedirection();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "RegalPay IDP Service");
});
app.ConfigureCustomExceptionMiddleware();
app.UseStaticFiles();
app.UseIdentityServer();
app.UseMvc();
app.UseMvcWithDefaultRoute();
}
public static IEnumerable GetClients()
{
return new List
{
new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.Implicit,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris = { "http://localhost:4200/auth-callback" },
PostLogoutRedirectUris = {"https://demo.identityserver.io/Account/Logout"},
AllowedCorsOrigins = {"http://localhost:4200"},
AllowedScopes = {IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api1"},
IdentityTokenLifetime = 60,
AccessTokenLifetime = 60,
AuthorizationCodeLifetime = 60,
AllowAccessTokensViaBrowser = true,
}
};
}
and my client configuration is
export function getClientSettings(): UserManagerSettings {
return {
authority: 'http://localhost:50000',
// client_id: 'angular_spa',
client_id: 'mvc',
// client_secret: 'secret',
redirect_uri: 'http://localhost:4200/auth-callback',
// post_logout_redirect_uri: 'http://localhost:4200/auth-callback',
//post_logout_redirect_uri: 'http://localhost:4200/home/',
post_logout_redirect_uri: 'https://demo.identityserver.io/Account/Logout',
//AllowedCorsOrigins = 'http://localhost:4200',
response_type:"id_token token",
// response_type: "token id_token",
scope:"openid profile api1",
filterProtocolClaims: true,
loadUserInfo: true //,
// automaticSilentRenew: true,
//silent_redirect_uri: 'http://localhost:4200/silent-refresh.html'
};
}