Skip to content

Commit 9392ed8

Browse files
Frank Robijnjosesimoes
authored andcommitted
Documentation for the latest change
1 parent e0e2080 commit 9392ed8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,50 @@ With the previous example the following happens:
196196

197197
All up, this is an example to show how to use authentication, it's been defined to allow flexibility.
198198

199+
The webserver supports having multiple authentication methods or credentials for the same route. Each pair of authentication method plus credentials should have its own method in the controller:
200+
201+
```csharp
202+
class MixedController
203+
{
204+
205+
[Route("sameroute")]
206+
[Authentication("Basic")]
207+
public void Basic(WebServerEventArgs e)
208+
{
209+
WebServer.OutPutStream(e.Context.Response, "sameroute: Basic");
210+
}
211+
212+
[Authentication("ApiKey:superKey1234")]
213+
[Route("sameroute")]
214+
public void Key(WebServerEventArgs e)
215+
{
216+
WebServer.OutPutStream(e.Context.Response, "sameroute: API key #1");
217+
}
218+
219+
[Authentication("ApiKey:superKey5678")]
220+
[Route("sameroute")]
221+
public void Key2(WebServerEventArgs e)
222+
{
223+
WebServer.OutPutStream(e.Context.Response, "sameroute: API key #2");
224+
}
225+
226+
[Route("sameroute")]
227+
public void None(WebServerEventArgs e)
228+
{
229+
WebServer.OutPutStream(e.Context.Response, "sameroute: Public");
230+
}
231+
}
232+
```
233+
The webserver selects the route for a request:
234+
235+
- If there are no matching methods, a not-found response (404) is returned.
236+
- If authentication information is passed in the header of the request, then only methods that require authentication are considered. If one of the method's credentials matches the credentials passed in the request, that method is called. Otherwise a non-authorized response (401) will be returned.
237+
- If no authentication information is passed in the header of the request:
238+
- If one of the methods does not require authentication, that method is called.
239+
- Otherwise a non-authorized response (401) will be returned. If one of the methods requires basic authentication, the `WWW-Authenticate` header is included to request credentials.
240+
241+
If two or more methods match the authentication method and credentials of the request, an internal server error is returned with a list of the methods.
242+
199243
## Managing incoming queries thru events
200244

201245
Very basic usage is the following:

0 commit comments

Comments
 (0)