Skip to content

Commit 113053b

Browse files
Copilotmarcominerva
andcommitted
Update README to document Roles support for single credentials
Co-authored-by: marcominerva <3522534+marcominerva@users.noreply.github.com>
1 parent 92de02f commit 113053b

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,26 @@ With this configuration, authentication will succedd if any of these credentials
201201

202202
**Assigning roles to API Keys and Basic Authentication credentials**
203203

204-
You can optionally specify roles for each API Key or Basic Authentication credential. When authentication succeeds, the specified roles will be automatically added as role claims to the user's identity:
204+
You can optionally specify roles for each API Key or Basic Authentication credential. When authentication succeeds, the specified roles will be automatically added as role claims to the user's identity.
205+
206+
For single credentials, you can specify roles directly:
207+
208+
```json
209+
"Authentication": {
210+
"ApiKey": {
211+
"ApiKeyValue": "f1I7S5GXa4wQDgLQWgz0",
212+
"UserName": "ApiUser",
213+
"Roles": ["Administrator"]
214+
},
215+
"Basic": {
216+
"UserName": "marco",
217+
"Password": "P@$$w0rd",
218+
"Roles": ["Administrator"]
219+
}
220+
}
221+
```
222+
223+
For multiple credentials, you can specify roles for each credential:
205224

206225
```json
207226
"Authentication": {
@@ -210,7 +229,7 @@ You can optionally specify roles for each API Key or Basic Authentication creden
210229
{
211230
"Value": "key-1",
212231
"UserName": "UserName1",
213-
"Roles": ["Admin", "User"]
232+
"Roles": ["Administrator", "User"]
214233
},
215234
{
216235
"Value": "key-2",
@@ -239,15 +258,15 @@ You can optionally specify roles for each API Key or Basic Authentication creden
239258
The `Roles` parameter is optional. If omitted, no role claims will be added to the user's identity. You can then use the standard ASP.NET Core authorization features to check for roles:
240259

241260
```csharp
242-
[Authorize(Roles = "Admin")]
261+
[Authorize(Roles = "Administrator")]
243262
public IActionResult AdminEndpoint()
244263
{
245-
return Ok("Admin access granted");
264+
return Ok("Administrator access granted");
246265
}
247266

248267
// Or with minimal APIs
249-
app.MapGet("/admin", () => "Admin access granted")
250-
.RequireAuthorization(policy => policy.RequireRole("Admin"));
268+
app.MapGet("/admin", () => "Administrator access granted")
269+
.RequireAuthorization(policy => policy.RequireRole("Administrator"));
251270
```
252271

253272
**Custom Authentication logic for API Keys and Basic Authentication**

0 commit comments

Comments
 (0)