Browse Source

Use the OpenIdConnectOptions.MapInboundClaims API introduced in ASP.NET Core 5.0

pull/1366/head
Kévin Chalet 5 years ago
parent
commit
2f6ed1ed4a
  1. 16
      samples/Mvc.Client/Startup.cs
  2. 8
      samples/Mvc.Server/Startup.cs

16
samples/Mvc.Client/Startup.cs

@ -1,4 +1,3 @@
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
@ -46,11 +45,8 @@ public class Startup
options.Scope.Add("offline_access"); options.Scope.Add("offline_access");
options.Scope.Add("demo_api"); options.Scope.Add("demo_api");
options.SecurityTokenValidator = new JwtSecurityTokenHandler // Disable the built-in JWT claims mapping feature.
{ options.MapInboundClaims = false;
// Disable the built-in JWT claims mapping feature.
InboundClaimTypeMap = new Dictionary<string, string>()
};
options.TokenValidationParameters.NameClaimType = "name"; options.TokenValidationParameters.NameClaimType = "name";
options.TokenValidationParameters.RoleClaimType = "role"; options.TokenValidationParameters.RoleClaimType = "role";
@ -74,8 +70,10 @@ public class Startup
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(options => options.MapControllerRoute( app.UseEndpoints(options =>
name: "default", {
pattern: "{controller=Home}/{action=Index}/{id?}")); options.MapControllers();
options.MapDefaultControllerRoute();
});
} }
} }

8
samples/Mvc.Server/Startup.cs

@ -189,8 +189,10 @@ public class Startup
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(options => options.MapControllerRoute( app.UseEndpoints(options =>
name: "default", {
pattern: "{controller=Home}/{action=Index}/{id?}")); options.MapControllers();
options.MapDefaultControllerRoute();
});
} }
} }

Loading…
Cancel
Save