diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index 73fe2b8b4..06dab4fae 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -39,6 +40,23 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) app.Run(async context => { + var authContext = new AuthenticateContext(CookieAuthenticationDefaults.AuthenticationScheme); + await context.Authentication.AuthenticateAsync(authContext); + if (context.Request.Path == new PathString("/remote-sign-out")) + { + var session = authContext.Properties[OpenIdConnectSessionProperties.SessionState]; + var sid = context.Request.Query["sid"]; + if (string.Equals(sid, session, System.StringComparison.Ordinal)) + { + await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + await context.Response.WriteAsync("Signed out remotely."); + return; + } + context.Response.StatusCode = 400; + await context.Response.WriteAsync("Missing or mismatched sid."); + return; + } + if (!context.User.Identities.Any(identity => identity.IsAuthenticated)) { await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" }); @@ -49,7 +67,17 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) } context.Response.ContentType = "text/plain"; - await context.Response.WriteAsync("Hello Authenticated User"); + await context.Response.WriteAsync("Hello Authenticated User\r\n"); + foreach (var claim in context.User.Claims) + { + await context.Response.WriteAsync($"{claim.Type}, {claim.Value}\r\n"); + } + foreach (var property in authContext.Properties) + { + await context.Response.WriteAsync($"{property.Key}, {property.Value}\r\n"); + } + + await context.Response.WriteAsync($"Logout: /remote-sign-out?sid={authContext.Properties[OpenIdConnectSessionProperties.SessionState]}\r\n"); }); } }