Skip to content

Commit a332a8a

Browse files
committed
Expand Simple Auth in docs
1 parent f091786 commit a332a8a

File tree

7 files changed

+106
-9
lines changed

7 files changed

+106
-9
lines changed

MyApp/_pages/releases/v8_05.md

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,14 @@ We're excited to migrate our templates to Kamal for deployments as it has distil
492492

493493
## Simple API Keys Credentials Auth Provider
494494

495-
We've improved the usability of [Simple Auth with API Keys](/auth/admin-apikeys) story with the new
496-
`ApiKeyCredentialsProvider` which enables .NET Microservices provide user session like behavior using
497-
simple API Keys which you'd configure together with the `AuthSecretAuthProvider` and `ApiKeysFeature` to enable
498-
a Credentials Auth implementation which users can use with their API Keys or Admin AuthSecret.
495+
The usability of the [Simple Auth with API Keys](/auth/admin-apikeys) story has
496+
been significantly improved with the new `ApiKeyCredentialsProvider` which enables .NET Microservices to provide
497+
persistent UserSession-like behavior using simple API Keys which can be configured together with the
498+
`AuthSecretAuthProvider` and `ApiKeysFeature` to enable a Credentials Auth implementation which users can
499+
use with their API Keys or Admin AuthSecret.
500+
501+
A typical configuration for .NET Microservices looking to enable Simple Auth access whose APIs are protected
502+
by API Keys and their Admin functionality protected by an Admin Auth Secret can be configured with:
499503

500504
```csharp
501505
public class ConfigureAuth : IHostingStartup
@@ -505,7 +509,7 @@ public class ConfigureAuth : IHostingStartup
505509
{
506510
services.AddPlugin(new AuthFeature([
507511
new ApiKeyCredentialsProvider(),
508-
new AuthSecretAuthProvider(AppConfig.Instance.AuthSecret),
512+
new AuthSecretAuthProvider("MyAuthSecret"),
509513
]));
510514
services.AddPlugin(new SessionFeature());
511515
services.AddPlugin(new ApiKeysFeature());
@@ -518,12 +522,105 @@ public class ConfigureAuth : IHostingStartup
518522
}
519523
```
520524

521-
When registered a Credentials Auth dialog will appear for [ServiceStack Built-in UIs](https://servicestack.net/auto-ui) allowing users to Sign In with their API Keys or Admin Auth Secret.
525+
When registered a Credentials Auth dialog will appear for [ServiceStack Built-in UIs](https://servicestack.net/auto-ui)
526+
allowing users to Sign In with their **API Keys** or Admin **Auth Secret**.
527+
528+
![](/img/pages/auth/simple/ai-server-auth-apiexplorer.png)
529+
530+
### Session Auth with API Keys
531+
532+
Behind the scenes this creates a Server [Auth Session](/auth/sessions)
533+
but instead of maintaining an Authenticated User Session it saves the API Key in the session then attaches the API Key to each request. This makes it possible to make API Key validated requests with just a session cookie instead of requiring resubmission of API Keys for each request.
534+
535+
### Secure .NET Microservices and Docker Appliances
536+
537+
This is an ideal Auth Configuration for .NET Docker Appliances and Microservices like [AI Server](/posts/ai-server) that don't need the complexity of ASP .NET Core's Identity Auth machinery and just want to restrict access to their APIs with API Keys and restrict Admin functionality to Administrator's with an Auth Secret.
538+
539+
The benefit of `ApiKeyCredentialsProvider` is that it maintains a persistent Session so that end users
540+
only need to enter their API Key a single time and they'll be able to navigate to all of AI Server's protected pages using their API Key maintained in their Server User Session without needing to re-enter it for each UI and every request.
541+
542+
### User Access with API Keys
543+
544+
AI Server uses **API Keys** to restrict Access to their AI Features to **authorized Users** with Valid API Keys who
545+
are able to use its Built-in UIs for its AI Features with the Users preferred Name and issued API Key:
546+
547+
![](/img/pages/auth/simple/ai-server-auth-user.png)
548+
549+
After signing in a single time they'll be able to navigate to any protected page and start using AI Server's AI features:
550+
551+
![](/img/pages/auth/simple/ai-server-auth-user-chat.png)
552+
553+
### User Access to API Explorer
554+
555+
This also lets users use their existing Auth Session across completely different UIs
556+
like [API Explorer](/api-explorer)
557+
where they'll have the same access to APIs as they would when calling APIs programatically with their API Keys, e.g:
558+
559+
![](/img/pages/auth/simple/ai-server-auth-apiexplorer-api.png)
560+
561+
### Coarse or fine-grained API Key access
562+
563+
By default **any** Valid API Key can access restricted services by `[ValidateApiKey]`
564+
565+
```csharp
566+
[ValidateApiKey]
567+
public class Hello : IGet, IReturn<HelloResponse>
568+
{
569+
public required string Name { get; set; }
570+
}
571+
```
572+
573+
### API Key Scopes
574+
575+
API Keys can be given elevated privileges where only Keys with user defined scopes:
576+
577+
![](/img/pages/auth/simple/admin-ui-apikeys-edit.png)
578+
579+
Are allowed to access APIs restricted with that scope:
580+
581+
```csharp
582+
[ValidateApiKey("todo:read")]
583+
public class QueryTodos : QueryDb<Todo>
584+
{
585+
public long? Id { get; set; }
586+
public List<long>? Ids { get; set; }
587+
public string? TextContains { get; set; }
588+
}
589+
```
590+
591+
### Restricted API Keys to specific APIs
592+
593+
API Keys can also be locked down to only be allowed to call specific APIs:
594+
595+
![](/img/pages/auth/simple/admin-ui-apikeys-restrict-to.png)
596+
597+
## Admin Access
598+
599+
AI Server also maintains an Admin UI and Admin APIs that are only accessible to **Admin** users who
600+
Authenticate with the App's configured Admin Auth Secret who are able to access AI Server's Admin
601+
UIs to monitor Live AI Requests, create new User API Keys, Manage registered AI Providers, etc.
602+
603+
![](/img/pages/auth/simple/ai-server-auth-admin-jobs.png)
604+
605+
### Admin Restricted APIs
606+
607+
You can restrict APIs to Admin Users by using `[ValidateAuthSecret]`:
608+
609+
```csharp
610+
[Tag(Tags.Admin)]
611+
[ValidateAuthSecret]
612+
[Api("Add an AI Provider to process AI Requests")]
613+
public class CreateAiProvider : ICreateDb<AiProvider>, IReturn<IdResponse>
614+
{
615+
//...
616+
}
617+
```
618+
619+
Which are identified in API Explorer with a **padlock** icon whilst APIs restricted by API Key are
620+
identified with a **key** icon:
522621

523-
![](/img/pages/auth/simple/apiexplorer-apikey-credentials.png)
622+
![](/img/pages/auth/simple/ai-server-auth-apiexplorer-admin.png)
524623

525-
Behind the scenes this creates a server session like normal [Session Auth](/auth/sessions) but instead of maintaining an Authenticated User Session it saves the API Key in the session then attaches the API Key to each request which is how it's able to make API Key validated requests with just a session cookie instead of resubmitting their API Key
526-
for each request.
527624

528625
## ServiceStack.Swift rewritten for Swift 6
529626

192 KB
Loading
135 KB
Loading
154 KB
Loading
128 KB
Loading
155 KB
Loading
62.3 KB
Loading

0 commit comments

Comments
 (0)