Jezz Santos - 137 - Feb 21, 2014

Is it possible to implement a ServiceStack web service that handles this the following kind of post request?


POST http://localhost:50001/oauth2/token HTTP/1.1
Authorization: Basic ZmFrZV9jbGllbnQ6ZmFrZV9zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: DotNetOpenAuth.Core/4.3.1.13153
Host: localhost:50001
Cache-Control: no-store,no-cache
Pragma: no-cache
Content-Length: 109
Expect: 100-continue
Proxy-Connection: Keep-Alive

username=satch&password=surfer101&scope=user_info%20some_other_scope%20try_changing_these&grant_type=password

Shouldn’t be any issue, ServiceStack handles form-url-encoded POSTs as well.

It’s possible, just create a Request DTO that matches the fields in the request body that has a route matching the /path/info.
You can access the Request details in your service with base.Request.

We also have a convenient extension method to read the BasicAuth header, see: https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/RequestFiltersTests.cs#L89

Jezz Santos:

thanks, will try that. I wasn’t sure if it was a dumb question, because its not a JSON or XML request.

Jezz Santos:

Is there a mechanism (presumably an attribute of some type) that I can add to a field in the DTO that changes the name of the actual form post field (mostly the case of it?

So for a DTO like this:
public class MyRequest
{
    string AccessToken {get; set;}
}
it actually handles the form post field ‘access-token’

You can use the DataContract attributes, but it’s also controls which properties get serialized so you’d also need attribute every member, e.g:

[DataContract]
public class MyRequest
{
    [DataMember(Name=“access-token”)]
    public string AccessToken {get; set;}
}

Jezz Santos:

thanks a lot
__________