We have implemented API versioning using headers, so in HttpClient on the mobile app code (Xamarin Forms), we do something like this:
_myHttpClient.DefaultRequestHeaders.Add(CustomRequestHeaders.ApiVersion, "2");
In the backend, we have a UsersController and a Users_v2Controller, and we need to consume the method GetUsersByRole.
UsersController:
[Authorize]
[RoutePrefix("api/Users")]
public class UsersController : BaseApiController
{
// ...
[HttpGet]
[Route("")]
public IHttpActionResult GetUsersByRole([FromUri] int clientId, [FromUri] string role)
{
if (ApiVersion == "2")
return RedirectToRoute("GetUsersByRole_v2", new { clientId = clientId, role = role });
return Ok ("V1 results");
}
// ...
}
Users_v2Controller:
[Authorize]
[RoutePrefix("api/Users")]
public class Users_v2Controller : BaseApiController
{
// ...
[HttpGet]
[Route("", Name = "GetUsersByRole_v2")]
public IHttpActionResult GetUsersByRole([FromUri] int clientId, [FromUri] string role)
{
return Ok ("V2 results");
}
// ...
}
Now, I am consuming the GET /api/users?clientId=1&role=Admin with ApiVersion=2 from android, iOS and Postman to double check:
Android: returns
V2 resultsPostman: returns
V2 resultsiOS: returns
401: unauthorizedbut if i setApiVersion=1it works and returnsV1 results
What could the problem be? Why would iOS say i am unauthorized?