Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 34bc9c5

Browse files
committed
#456 Unify OIDC Code/IdToken/Hybride flows.
1 parent bbcabc0 commit 34bc9c5

File tree

2 files changed

+227
-238
lines changed

2 files changed

+227
-238
lines changed

samples/OpenIdConnectSample/Startup.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using Microsoft.AspNetCore.Authentication.Cookies;
34
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
@@ -34,6 +35,28 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
3435
{
3536
loggerfactory.AddConsole(LogLevel.Information);
3637

38+
// Simple error page
39+
app.Use(async (context, next) =>
40+
{
41+
try
42+
{
43+
await next();
44+
}
45+
catch (Exception ex)
46+
{
47+
if (!context.Response.HasStarted)
48+
{
49+
context.Response.Clear();
50+
context.Response.StatusCode = 500;
51+
await context.Response.WriteAsync(ex.ToString());
52+
}
53+
else
54+
{
55+
throw;
56+
}
57+
}
58+
});
59+
3760
app.UseIISPlatformHandler();
3861

3962
app.UseCookieAuthentication(new CookieAuthenticationOptions
@@ -52,17 +75,30 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
5275

5376
app.Run(async context =>
5477
{
78+
if (context.Request.Path.Equals("/signout"))
79+
{
80+
await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
81+
context.Response.ContentType = "text/html";
82+
await context.Response.WriteAsync($"<html><body>Signing out {context.User.Identity.Name}<br>{Environment.NewLine}");
83+
await context.Response.WriteAsync("<a href=\"/\">Sign In</a>");
84+
await context.Response.WriteAsync($"</body></html>");
85+
return;
86+
}
87+
5588
if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
5689
{
5790
await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
58-
59-
context.Response.ContentType = "text/plain";
60-
await context.Response.WriteAsync("Hello First timer");
6191
return;
6292
}
6393

64-
context.Response.ContentType = "text/plain";
65-
await context.Response.WriteAsync("Hello Authenticated User");
94+
context.Response.ContentType = "text/html";
95+
await context.Response.WriteAsync($"<html><body>Hello Authenticated User {context.User.Identity.Name}<br>{Environment.NewLine}");
96+
foreach (var claim in context.User.Claims)
97+
{
98+
await context.Response.WriteAsync($"{claim.Type}: {claim.Value}<br>{Environment.NewLine}");
99+
}
100+
await context.Response.WriteAsync("<a href=\"/signout\">Sign Out</a>");
101+
await context.Response.WriteAsync($"</body></html>");
66102
});
67103
}
68104

0 commit comments

Comments
 (0)