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

Commit e6890e4

Browse files
committed
Disable the built-in OIDC claims mapping feature in the client samples
1 parent 9d5d938 commit e6890e4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

samples/Mvc/Mvc.Client/Startup.cs

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IdentityModel.Tokens.Jwt;
24
using System.Net.Http;
35
using Microsoft.AspNetCore.Authentication.Cookies;
46
using Microsoft.AspNetCore.Builder;
@@ -43,6 +45,15 @@ public void ConfigureServices(IServiceCollection services)
4345
// retrieve the identity provider's configuration and spare you from setting
4446
// the different endpoints URIs or the token validation parameters explicitly.
4547
options.Authority = "http://localhost:54540/";
48+
49+
options.SecurityTokenValidator = new JwtSecurityTokenHandler
50+
{
51+
// Disable the built-in JWT claims mapping feature.
52+
InboundClaimTypeMap = new Dictionary<string, string>()
53+
};
54+
55+
options.TokenValidationParameters.NameClaimType = "name";
56+
options.TokenValidationParameters.RoleClaimType = "role";
4657
});
4758

4859
services.AddMvc();

samples/Nancy/Nancy.Client/Startup.cs

+14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IdentityModel.Tokens.Jwt;
34
using System.Net.Http;
45
using System.Security.Claims;
56
using System.Threading.Tasks;
67
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
8+
using Microsoft.IdentityModel.Tokens;
79
using Microsoft.Owin.Security;
810
using Microsoft.Owin.Security.Cookies;
911
using Microsoft.Owin.Security.OpenIdConnect;
@@ -48,6 +50,18 @@ public void Configuration(IAppBuilder app)
4850

4951
Scope = "openid profile offline_access",
5052

53+
SecurityTokenValidator = new JwtSecurityTokenHandler
54+
{
55+
// Disable the built-in JWT claims mapping feature.
56+
InboundClaimTypeMap = new Dictionary<string, string>()
57+
},
58+
59+
TokenValidationParameters = new TokenValidationParameters
60+
{
61+
NameClaimType = "name",
62+
RoleClaimType = "role"
63+
},
64+
5165
// Note: by default, the OIDC client throws an OpenIdConnectProtocolException
5266
// when an error occurred during the authentication/authorization process.
5367
// To prevent a YSOD from being displayed, the response is declared as handled.

0 commit comments

Comments
 (0)