Skip to content

Commit f0f5789

Browse files
committed
Update text based on PR feedback
1 parent 4a9e039 commit f0f5789

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

aspnetcore/security/authentication/configure-oidc-web-authentication.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ builder.Services.AddAuthentication(options =>
7070

7171
options.SaveTokens = true;
7272
options.GetClaimsFromUserInfoEndpoint = true;
73-
options.TokenValidationParameters = new TokenValidationParameters
74-
{
75-
NameClaimType = "name"
76-
};
73+
74+
options.MapInboundClaims = false;
75+
options.TokenValidationParameters.NameClaimType = JwtRegisteredClaimNames.Name;
76+
options.TokenValidationParameters.RoleClaimType = "roles";
7777
});
7878
```
7979

@@ -114,6 +114,8 @@ app.UseHttpsRedirection();
114114
app.UseStaticFiles();
115115

116116
app.UseRouting();
117+
// Authorization is required for middleware
118+
// after the UseAuthorization method
117119
app.UseAuthorization();
118120
app.MapRazorPages();
119121
```
@@ -129,13 +131,10 @@ Add the Authorize attribute to the protected razor pages, for example the Index.
129131
A better way would be to force the whole application to be authorized and opt out for unsecure pages
130132

131133
```csharp
132-
builder.services.AddRazorPages().AddMvcOptions(options =>
133-
{
134-
var policy = new AuthorizationPolicyBuilder()
135-
.RequireAuthenticatedUser()
136-
.Build();
137-
options.Filters.Add(new AuthorizeFilter(policy));
138-
});
134+
builder.Services.AddAuthorizationBuilder()
135+
.SetFallbackPolicy(new AuthorizationPolicyBuilder()
136+
.RequireAuthenticatedUser()
137+
.Build());
139138
```
140139

141140
### Add a new Logout.cshtml and SignedOut.cshtml Razor page to the project

0 commit comments

Comments
 (0)