Eric
Eric

Reputation: 472

ServiceStack.net with Custom CredentialsAuthProvider returning "Unauthorized"?

I'm trying to use ServiceStack.net so my first service has implemented a Custom CredentialsAuthProvider who's TryAuthenticate method simply returns True at the moment.

The problem I'm having is that the client first calls (and Succeeds)

var rc = new JsonServiceClient("http://localhost:1337/");

var ar = rc.Send<AuthResponse>(new Auth
{
  provider = CredentialsAuthProvider.Name,
  UserName = "user",
  Password = "p@55word",
  RememberMe = true
});

Followed by:

var newJob = rc.Post<BladeJob>("/jobs", new BladeJob { Name = "TestJob" }); //todo.Id = 

Which simply returns "Unauthorized" (Exception).

The service is quite simple:

[Authenticate()]
public class BladesService : RestServiceBase<BladeJob>
{
  public JobRepository Repository { get; set; }

  public override object OnPut(BladeJob request)
  {
    return Repository.Store(request);
  }

public override object OnPost(BladeJob job)
{
  return Repository.Store(job);
}

  public override object OnGet(BladeJob request)
  {
    IAuthSession session = this.GetSession();

    if (request.JobID != default(ulong))
      return Repository.GetByID(request.JobID);

    return Repository.GetAll();
    }
}

I put a breakpoint in the TryAuthenticate and it hits it just fine, what am I doing wrong?

The entire Host Configure is here:

public override void Configure(Funq.Container container)
{
  //Register Web Service dependencies
  container.Register(new JobRepository());
  //Register all Authentication methods you want to enable for this web app.
  Plugins.Add(new AuthFeature(() => new AuthUserSession(),
      new AuthProvider[] {
        new CustomCredentialsAuthProvider() //HTML Form post of UserName/Password credentials
      }
  ));

  //Register user-defined REST-ful routes         
  Routes
    .Add<BladeJob>("/jobs")
    .Add<BladeJob>("/jobs/{JobID}");

Upvotes: 1

Views: 1211

Answers (1)

mythz
mythz

Reputation: 143319

You should register an ICacheClient that the Session Provider should use.

E.g. you can register an In-Memory cache with:

container.Register<ICacheClient>(new MemoryCacheClient());

Here are other Caching providers available for ServiceStack.

Note: As this is caught a few people unexpectedly, so in the next version of ServiceStack (v3.9.12+) we will auto-register to use an InMemory Cache if one is not specified.

Upvotes: 2

Related Questions