I'm trying to access my custom AuthProvider (which in inherited from BasicAuthProvider) from ServerEventsClient. Provider code is very simple ATM
public class RoomsAuthProvider : BasicAuthProvider
{
public RoomsAuthProvider(AppSettings appSettings) : base(appSettings)
{
}
public RoomsAuthProvider()
{
}
public override bool TryAuthenticate(IServiceBase authService,
string userName, string password)
{
return true;
}
public override IHttpResult OnAuthenticated(IServiceBase authService,
IAuthSession session, IAuthTokens tokens,
Dictionary<string, string> authInfo)
{
session.FirstName = "some_firstname_from_db";
return base.OnAuthenticated(authService, session, tokens, authInfo);
}
}
I'm registering it as usual:
public override void Configure(Funq.Container container)
{
container.Register<ICacheClient>(new MemoryCacheClient());
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[]
{
new RoomsAuthProvider()
}));
Plugins.Add(new ServerEventsFeature());
}
and my client is:
var client = new ServerEventsClient("http://localhost:1337/", "home")
trying to authenticate:
var authResponse = client.Authenticate(new Authenticate
{
provider = "RoomsAuthProvider",
UserName = "[email protected]",
Password = "p@55w0rd",
RememberMe = true,
});
I always get NotFound error and the rror stating that no configuration is set for this AuthProvider. Setting Name and Realm in provider didn't help. Is there another authentication flow for this type of client or I'm missing something? Any ideas are welcome
When you inherit a BasicAuthProvider you also inherit it's provider name which unless you override it, is by default is "basic" (i.e. it's not the name of inherited class).
But the BasicAuthProvider
implements HTTP Basic Auth so you're meant to call it via HTTP Basic Authentication not via a Web Service call.
If you're trying to authenticate via a Web Service call you should inherit from CredentialsAuthProvider instead which is the authentication method used for authenticating via Username/Password like you're doing in your example. The provider name for CredentialsAuthProvider
is credentials so your client call would then be:
var authResponse = client.Authenticate(new Authenticate
{
provider = "credentials",
UserName = "[email protected]",
Password = "p@55w0rd",
RememberMe = true,
});