Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure client for access with authsecret?

Tags:

servicestack

I'm using the client and I need to call a service using authsecret parameter. If I ad this param to the base url it give me a serialization error.

String baseUrl = AppConfig.GetAppApiUrl();
var client = new JsonServiceClient(baseUrl.AddQueryParam("authsecret","secretz123!"));
var c = client.Send(new ComuneRequest { Id = "A001" });

Using Fiddler I discovered that the request that the client generate is incorrect:

POST http://192.168.0.63:820/?authsecret=secretz123%21/json/reply/ComuneRequest

So, what I have to do to make the client create a request in a correct format?

like image 603
Marco Staffoli Avatar asked Jan 28 '26 17:01

Marco Staffoli


1 Answers

It needs to be sent as a Request Parameter (i.e. QueryString or FormData) which you can do using HTTP Utils with:

var url = baseUrl.CombineWith(requestDto.ToUrl()).AddQueryParam("authsecret", secret);
var res = url.GetJsonFromUrl().FromJson<MyResponse>();

Otherwise since AuthSecret is not a property on your Request DTO you wont be able to send it as a Request Parameter in the Request Body, but you should be able to send the param in the Request Headers with:

var client = new JsonServiceClient(baseUrl) {
    RequestFilter = req => req.Headers[HttpHeaders.XParamOverridePrefix+"authsecret"] = secret
};
like image 72
mythz Avatar answered Jan 31 '26 07:01

mythz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!