|
3 | 3 |
|
4 | 4 | using System.Globalization;
|
5 | 5 | using System.Net.Http;
|
| 6 | +using System.Security.Claims; |
6 | 7 | using System.Text.Encodings.Web;
|
7 | 8 | using System.Text.Json;
|
8 | 9 | using Microsoft.AspNetCore.Authentication;
|
9 | 10 | using Microsoft.AspNetCore.Authentication.Cookies;
|
| 11 | +using Microsoft.AspNetCore.Authentication.OAuth.Claims; |
10 | 12 | using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
11 | 13 | using Microsoft.Extensions.Options;
|
12 | 14 | using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
@@ -102,15 +104,18 @@ public void ConfigureServices(IServiceCollection services)
|
102 | 104 | o.Authority = Configuration["oidc:authority"];
|
103 | 105 | */
|
104 | 106 | // https://github.com/IdentityServer/IdentityServer4.Demo/blob/master/src/IdentityServer4Demo/Config.cs
|
105 |
| - o.ClientId = "hybrid"; |
| 107 | + o.ClientId = "interactive.confidential"; |
106 | 108 | o.ClientSecret = "secret"; // for code flow
|
107 |
| - o.Authority = "https://demo.identityserver.io/"; |
| 109 | + o.Authority = "https://demo.duendesoftware.com/"; |
108 | 110 |
|
109 |
| - o.ResponseType = OpenIdConnectResponseType.CodeIdToken; |
| 111 | + o.ResponseType = OpenIdConnectResponseType.Code; |
110 | 112 | o.SaveTokens = true;
|
111 | 113 | o.GetClaimsFromUserInfoEndpoint = true;
|
112 | 114 | o.AccessDeniedPath = "/access-denied-from-remote";
|
113 |
| - o.MapInboundClaims = false; |
| 115 | + // o.MapInboundClaims = false; |
| 116 | + o.ClaimsIssuer = "MyCustomIssuer"; |
| 117 | + |
| 118 | + o.ClaimActions.Add(new IssuerFixupAction()); |
114 | 119 |
|
115 | 120 | // o.ClaimActions.MapAllExcept("aud", "iss", "iat", "nbf", "exp", "aio", "c_hash", "uti", "nonce");
|
116 | 121 |
|
@@ -352,5 +357,20 @@ private static async Task WriteTableHeader(HttpResponse response, IEnumerable<st
|
352 | 357 |
|
353 | 358 | private static string HtmlEncode(string content) =>
|
354 | 359 | string.IsNullOrEmpty(content) ? string.Empty : HtmlEncoder.Default.Encode(content);
|
| 360 | + |
| 361 | + private class IssuerFixupAction : ClaimAction |
| 362 | + { |
| 363 | + public IssuerFixupAction() : base(ClaimTypes.NameIdentifier, string.Empty) { } |
| 364 | + |
| 365 | + public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) |
| 366 | + { |
| 367 | + var oldClaims = identity.Claims.ToList(); |
| 368 | + foreach (var claim in oldClaims) |
| 369 | + { |
| 370 | + identity.RemoveClaim(claim); |
| 371 | + identity.AddClaim(new Claim(claim.Type, claim.Value, claim.ValueType, issuer, claim.OriginalIssuer, claim.Subject)); |
| 372 | + } |
| 373 | + } |
| 374 | + } |
355 | 375 | }
|
356 | 376 |
|
0 commit comments