forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicAuthProvider.cs
More file actions
33 lines (27 loc) · 1.09 KB
/
Copy pathBasicAuthProvider.cs
File metadata and controls
33 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using ServiceStack.Configuration;
using ServiceStack.Host;
namespace ServiceStack.Auth
{
public class BasicAuthProvider : CredentialsAuthProvider
{
public new static string Name = AuthenticateService.BasicProvider;
public new static string Realm = "/auth/" + AuthenticateService.BasicProvider;
public BasicAuthProvider()
{
this.Provider = Name;
this.AuthRealm = Realm;
}
public BasicAuthProvider(IAppSettings appSettings)
: base(appSettings, Realm, Name) {}
public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
var httpReq = authService.Request;
var basicAuth = httpReq.GetBasicAuthUserAndPassword();
if (basicAuth == null)
throw HttpError.Unauthorized("Invalid BasicAuth credentials");
var userName = basicAuth.Value.Key;
var password = basicAuth.Value.Value;
return Authenticate(authService, session, userName, password, request.Continue);
}
}
}