I have implemented JWT in swagger, token is generated correctly and works fine.
Recap API: one interface and one class
public interface ITokenRepository
{
Tokens Authenticate(Users users);
}
public class TokenRepository : ITokenRepository
{
Dictionary<string, string> UsersRecords = new Dictionary<string, string>
{
{ "myuser","mypass"},
{ "user","password"}
};
….. more code
The controller
public CourseService _courseservice;
private readonly ITokenRepository _tokenRepository;
public CourseController(CourseService courseservice,ITokenRepository tokenRepository)
{
_courseservice = courseservice;
_tokenRepository = tokenRepository;
}
[HttpPost]
[Route("GetToken")]
public IActionResult Authenticate(Users usersdata)
{
var token = _tokenRepository.Authenticate(usersdata);
if (token == null)
{
return Unauthorized();
}
return Ok(token);
}
I have a ASP.NET Core Web app (MVC) with Razor view do display some basic end-points but I am struggling to generate the token from the web client.
If run from swagger UI or Postman and pass user/password, it generates the token fine). I just need to learn how to generate the token from the web client.
Thank you