-
Notifications
You must be signed in to change notification settings - Fork 15
[identity] add IsMachine extension and identity:users.read claim type for read-only operation is UserApi
#1003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -294,7 +294,7 @@ public static IExtendedIdentityServerBuilder AddExtendedEndpoints(this IExtended | |||||
| authOptions.AddPolicy(IdentityEndpoints.Policies.BeUsersReader, policy => { | ||||||
| policy.AddAuthenticationSchemes(IdentityEndpoints.AuthenticationScheme) | ||||||
| .RequireAuthenticatedUser() | ||||||
| .RequireAssertion(x => x.User.HasScope(IdentityEndpoints.SubScopes.Users) && x.User.CanReadUsers()); | ||||||
| .RequireAssertion(x => (x.User.HasScope(IdentityEndpoints.SubScopes.Users) && x.User.CanReadUsers()) || (x.User.HasScope(IdentityEndpoints.SubScopes.UsersRead) && x.User.IsMachine())); | ||||||
| }); | ||||||
|
Comment on lines
294
to
298
|
||||||
| authOptions.AddPolicy(IdentityEndpoints.Policies.BeUsersWriter, policy => { | ||||||
| policy.AddAuthenticationSchemes(IdentityEndpoints.AuthenticationScheme) | ||||||
|
|
@@ -334,7 +334,7 @@ public static IExtendedIdentityServerBuilder AddExtendedEndpoints(this IExtended | |||||
| authOptions.AddPolicy(IdentityEndpoints.Policies.BeLogsReader, policy => { | ||||||
| policy.AddAuthenticationSchemes(IdentityEndpoints.AuthenticationScheme) | ||||||
| .RequireAuthenticatedUser() | ||||||
| .RequireAssertion(x => x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && x.User.CanReadUsers()); | ||||||
| .RequireAssertion(x => (x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && x.User.CanReadUsers()) || (x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && x.User.IsMachine())); | ||||||
|
||||||
| .RequireAssertion(x => (x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && x.User.CanReadUsers()) || (x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && x.User.IsMachine())); | |
| .RequireAssertion(x => x.User.HasScope(IdentityEndpoints.SubScopes.Logs) && (x.User.CanReadUsers() || x.User.IsMachine())); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ public static RouteGroupBuilder MapManageUsers(this IdentityServerEndpointRouteB | |
| group.WithTags("Users"); | ||
| group.WithGroupName("identity"); | ||
| // Add security requirements, all incoming requests to this API *must* be authenticated with a valid user. | ||
| var allowedScopes = new[] { options.ApiScope, IdentityEndpoints.SubScopes.Users }.FilterOutNulls().ToArray(); | ||
| var allowedScopes = new[] { options.ApiScope, IdentityEndpoints.SubScopes.Users , IdentityEndpoints.SubScopes.UsersRead }.FilterOutNulls().ToArray(); | ||
|
||
| group.RequireAuthorization(policy => policy | ||
| .RequireAuthenticatedUser() | ||
| .AddAuthenticationSchemes(IdentityEndpoints.AuthenticationScheme) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsMachineusesprincipal.Identity?.IsAuthenticated, which only reflects the first identity on the principal. If a principal contains multiple identities, this can incorrectly return false even when another identity is authenticated. Consider usingprincipal.Identities.Any(i => i.IsAuthenticated)(or, since callers already useRequireAuthenticatedUser(), dropping the authentication check and only checking the absence of subject id).