0

I need to use a JSON object as an authentication in Servicestack V.4.0.22. The object is in the body of an HTTP POST:

{ "username":"santaclaus","password":"verysecret","customfield":"stuff" }

From what I have read from other similar questions the solution should be to create a custom authentication provider extending CredentialsAuthProvider, but somehow IServiceBase authService does not contain the original request input.

How do I access the original request?

Scott
  • 21,211
  • 8
  • 65
  • 72

1 Answers1

1

You can access the original Request with:

authService.Request

The Request DTO with:

authService.Request.Dto

Or the underlying ASP.NET HttpRequest with:

var aspReq = (HttpRequestBase)authService.Request.OriginalRequest;
mythz
  • 141,670
  • 29
  • 246
  • 390
  • hmm i did try going through each field of the authService.Request, but the fields RawBody, FormData & the inputStream came up empty. The Dto which got filled with the username & password but of course couldn´t get mapped with the customfield, the content length was correct, the headers correct. Its also running selfhost by the way – user1005003 Jul 16 '14 at 18:49
  • `FormData` is only populated for POST'ed form urlencoded variables (e.g. HTML Form Post not JSON). If you want to reread the Request InputStream you need to [buffer the Request Stream](https://github.com/ServiceStack/ServiceStack/blob/master/release-notes.md#buffered-stream-option-has-now-added-to-response). – mythz Jul 16 '14 at 19:05
  • That did the trick, thank you. I'll look through the updates more thoroughly from now on. – user1005003 Jul 17 '14 at 09:29