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
38 lines (30 loc) · 1.18 KB
/
BasicAuthProvider.cs
File metadata and controls
38 lines (30 loc) · 1.18 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
34
35
36
37
38
using ServiceStack.Common.Web;
using ServiceStack.Configuration;
using ServiceStack.ServiceHost;
namespace ServiceStack.ServiceInterface.Auth
{
public class BasicAuthProvider : CredentialsAuthProvider
{
public new static string Name = AuthService.BasicProvider;
public new static string Realm = "/auth/" + AuthService.BasicProvider;
public BasicAuthProvider()
{
this.Provider = Name;
this.AuthRealm = Realm;
}
public BasicAuthProvider(IResourceManager appSettings)
: base(appSettings, Realm, Name)
{
}
public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
{
var httpReq = authService.RequestContext.Get<IHttpRequest>();
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);
}
}
}