Skip to content

Commit b233af2

Browse files
committed
Add docs for new v8.7 features
1 parent dcbfbeb commit b233af2

20 files changed

+573
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Claims are attestations or attributes about a User which we can use to restrict access to APIs to only Users who
2+
have been assigned that claim. We could use this to implement a permission system that restricts usage with a
3+
`todos:write` permission with something like:
4+
5+
```csharp
6+
[ValidateHasClaim("perm", "todos:write")]
7+
class CreateTodo {}
8+
```
9+
10+
Normally this would result in the generic missing claims error message:
11+
12+
:::{.not-prose}
13+
<error-summary :status="{message:`perm Claim with 'todos:write' is Required`}"></error-summary>
14+
:::
15+
16+
But as the `perm` claim has a customized error message:
17+
18+
```csharp
19+
HasClaimValidator.ClaimErrorMessages["perm"]= "`${Value} Permission Required`";
20+
```
21+
22+
It will generate that Error Response instead:
23+
24+
:::{.not-prose}
25+
<error-summary :status="{message:`'todos:write' Permission Required`}"></error-summary>
26+
:::
27+
28+
Which is a good example showing how `HasClaimValidator.ClaimErrorMessages` can be used to add custom error messages
29+
for your own custom claim validation.
30+
31+
### Inspecting Claims inside Services
32+
33+
You can also inspect and validate a Users Claim by inspecting the Authenticated ClaimsPrincipal, e.g:
34+
35+
```csharp
36+
public class TodoServices : Service
37+
{
38+
public object Any(CreateTodo request)
39+
{
40+
var user = Request.GetClaimsPrincipal();
41+
if (!user.HasClaim("perm", "todos:write"))
42+
throw HttpError.Forbidden("todos:write Permission Required");
43+
44+
var allUserClaims = user.Claims.ToList();
45+
//...
46+
}
47+
}
48+
```
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Identity Roles & Claims UI
3+
---
4+
5+
The Roles Admin UI is enabled when registering the [Admin Users UI](/admin-ui-identity-users#registration)
6+
which enables management APIs and Admin UIs for managing Identity Auth Roles and Claims for both Users and Roles.
7+
8+
Once registered it will be available from the **Roles** menu item in the Admin UI sidebar which can be used Add and Remove Application Roles:
9+
10+
![](/img/pages/admin-ui/identityauth-roles.webp)
11+
12+
### Custom Application Roles
13+
14+
If your App uses an extended `IdentityRole` data model, it can be configured with:
15+
16+
```csharp
17+
services.AddPlugin(
18+
new AuthFeature(IdentityAuth.For<ApplicationUser,ApplicationRole>(...)));
19+
```
20+
21+
If it's also configured to use a different `PrimaryKey` type, it can be configured with:
22+
23+
```csharp
24+
services.AddPlugin(
25+
new AuthFeature(IdentityAuth.For<AppUser,AppRole,int>(...)));
26+
```
27+
28+
### IdentityAuth Role Claims
29+
30+
The Edit Role Admin UI can also be configured to Add/Remove Claims to a Role, e.g:
31+
32+
![](/img/pages/admin-ui/identityauth-role-claims.webp)
33+
34+
Any Added or Removed Claims are only applied after clicking **Update Role**, likewise you can exit the UI without applying any changes by clicking **Cancel**.
35+
36+
### Behavior of Role Claims
37+
38+
Claims added to Roles have similar behavior to having Claims individually applied to all Users with that Role such that
39+
when a User is Authenticated they're populated with all claims assigned to their Roles and their individual User Claims.
40+
41+
## Validating Claims
42+
43+
::include admin-ui-claims-validation.md::

MyApp/_pages/admin-ui-identity-users.md

+9
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,12 @@ feature.OnBeforeDeleteUser = (request, userId) => { ... };
162162
feature.OnAfterDeleteUser = (request, userId) => { ... };
163163
```
164164

165+
### IdentityAuth User Claims
166+
167+
The User Claim Management UI can be used to assign Claims to individual Users:
168+
169+
![](/img/pages/admin-ui/identityauth-user-claims.webp)
170+
171+
## Validating Claims
172+
173+
::include admin-ui-claims-validation.md::

0 commit comments

Comments
 (0)