I am testing the generated c# types and two clients and am having issues with the new JsonApiClient. Just following the documentation the following cases. How does the new Api client work, this is a non async test in a console app (void main()):
//seems to append /api tried https://redacted/api/ as well
var client = new JsonApiClient("https://redacted.com/");
//AuthenticateResponse isAuth;
var isAuth = client.Api(new Authenticate()
{
UserName = "redacted",
Password = "redacted",
RememberMe = true,
provider = "credentials"
});
// isauth never has a Response here, completed==false
client.SetTokenCookie(isAuth.Response.BearerToken);
Is there an isAuth.Error? Try share as much detail about the HTTP request/response as you can as it helps others have more context of what the issue might be.
Testing the JsonApiClient with our blazor-wasm-api.jamstacks.net live demo for example, both respond correctly as expected. Note, this demo is configured with JWT and as expected does not return a BearerToken in the response body but instead in the ss-tok cookies which persist in the client. The clients are both then authenticated to make API calls that required auth.
ss-tok contains the bearer token should be visible is both clients. See the example code below:
using ServiceStack;
Console.WriteLine("Hello, World!");
var client = new JsonApiClient("https://blazor-wasm-api.jamstacks.net");
var serviceClient = new JsonServiceClient("https://blazor-wasm-api.jamstacks.net");
//AuthenticateResponse isAuth;
var isAuth = client.Api(new Authenticate()
{
UserName = "admin@email.com",
Password = "p@55wOrd",
RememberMe = true,
provider = "credentials"
});
var isAuthService = serviceClient.Send(new Authenticate
{
UserName = "admin@email.com",
Password = "p@55wOrd",
RememberMe = true,
provider = "credentials"
});
Console.WriteLine($"{nameof(isAuth)}.{nameof(isAuth.Response.BearerToken)}: {isAuth.Response.BearerToken ?? "null"}");
Console.WriteLine($"{nameof(isAuthService)}.{nameof(isAuthService.BearerToken)}: {isAuthService.BearerToken ?? "null"}");
Console.WriteLine($"{serviceClient.GetCookieValues()["ss-tok"]}");
Console.WriteLine($"{client.GetCookieValues()["ss-tok"]}");
var secureHelloResponseService = serviceClient.Send(new HelloSecure { Name = "World" });
var secureHelloResponseApi = client.Api(new HelloSecure { Name = "World" });
Console.WriteLine($"Service: {secureHelloResponseService.Result}");
Console.WriteLine($"Api: {secureHelloResponseApi.Response.Result}");
public class HelloSecure : IReturn<HelloResponse>
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
Possible that depending on your ServiceStack server you are connecting to (different version, AuthFeature config etc) could be causing an issue.
The c# client is using the newest service stack client, 6.0.2 but the server is 5.10.4 at this moment. I realized that they probably aren’t compatible as it is returning a 404 so tthe 6.x branch I think sets up some different paths (/api if I recall).