This repository was archived by the owner on Dec 24, 2020. It is now read-only.
File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Collections . Generic ;
3
+ using System . IdentityModel . Tokens . Jwt ;
2
4
using System . Net . Http ;
3
5
using Microsoft . AspNetCore . Authentication . Cookies ;
4
6
using Microsoft . AspNetCore . Builder ;
@@ -43,6 +45,15 @@ public void ConfigureServices(IServiceCollection services)
43
45
// retrieve the identity provider's configuration and spare you from setting
44
46
// the different endpoints URIs or the token validation parameters explicitly.
45
47
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" ;
46
57
} ) ;
47
58
48
59
services . AddMvc ( ) ;
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IdentityModel . Tokens . Jwt ;
3
4
using System . Net . Http ;
4
5
using System . Security . Claims ;
5
6
using System . Threading . Tasks ;
6
7
using Microsoft . IdentityModel . Protocols . OpenIdConnect ;
8
+ using Microsoft . IdentityModel . Tokens ;
7
9
using Microsoft . Owin . Security ;
8
10
using Microsoft . Owin . Security . Cookies ;
9
11
using Microsoft . Owin . Security . OpenIdConnect ;
@@ -48,6 +50,18 @@ public void Configuration(IAppBuilder app)
48
50
49
51
Scope = "openid profile offline_access" ,
50
52
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
+
51
65
// Note: by default, the OIDC client throws an OpenIdConnectProtocolException
52
66
// when an error occurred during the authentication/authorization process.
53
67
// To prevent a YSOD from being displayed, the response is declared as handled.
You can’t perform that action at this time.
0 commit comments