I am trying to use Refit but am having an issue it says its cant find my authenticate method when trying to login a user form the client side. Refit is a strongly typed httpclient replacement. Im wondering is it cause I'm using the FromBody attribute in the swagger side?
Base url is stored in a var
public const string APIUrl = "https://localhost:44315/api";
public interface ILoginAPI
{
[Post("/Users/")]
Task<Token> Authenticate(User user);
}
My user Controller has the function defined as
[AllowAnonymous]
[HttpPost("Authenticate")]
public IActionResult Authenticate([FromBody] AuthenticateRequest model) {
var response = _userService.Authenticate(model, ipAddress());
if (response == null)
return BadRequest(new { message = "Username or password is incorrect" });
setTokenCookie(response.JwtToken);
return Ok(response);
}
My Token is here as a class
public class Token
{
public bool Authenticated { get; set; }
public string Created { get; set; }
public string Expiration { get; set; }
public string AccessToken { get; set; }
public string Message { get; set; }
}
And here is me trying to consume it its a web api project that has jwt berrer token and that functionality works as it stands.
public IActionResult Index()
{
var loginAPI = RestService.For<ILoginAPI>(Constants.APIUrl);
Token token = loginAPI.Authenticate(
new User()
{
Username = "David",
Password = "Test12345",
}).Result;
var mytokenHere = JsonConvert.SerializeObject(token);
var test = token.Authenticated;
return View();
}
Cause when I look at swagger ui all it shows me is username and passsword here which works.
Results
But why when I am attempting to do it thru refit is it not finding the api call.