Browse Source

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

pull/1366/head
Kévin Chalet 4 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.OpenIdConnect;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
@ -46,11 +45,8 @@ public class Startup
options.Scope.Add("offline_access");
options.Scope.Add("demo_api");
options.SecurityTokenValidator = new JwtSecurityTokenHandler
{
// Disable the built-in JWT claims mapping feature.
InboundClaimTypeMap = new Dictionary<string, string>()
};
// Disable the built-in JWT claims mapping feature.
options.MapInboundClaims = false;
options.TokenValidationParameters.NameClaimType = "name";
options.TokenValidationParameters.RoleClaimType = "role";
@ -74,8 +70,10 @@ public class Startup
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(options => options.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"));
app.UseEndpoints(options =>
{
options.MapControllers();
options.MapDefaultControllerRoute();
});
}
}

8
samples/Mvc.Server/Startup.cs

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

Loading…
Cancel
Save