Ok, so first - to run some error checking outside of your app, clear your browser cache or any other caching mechanisms that might be storing the old token as this might become an issue.
I have converted your code to what I think might work, again, more information leads to an absolute solution... -
[Route("api/[controller]")]
[ApiController]
public class loginController : ControllerBase
{
[HttpGet("token")]
[AllowAnonymous]
public IActionResult GetToken()
{
try
{
var model = new UserModel { UserName = "ah", Password = "123" };
var token = GenerateToken(model);
return Ok(new { token = token });
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}
}
Now you can make a 'GET' request to 'https://localhost:7107/api/login/token'. After obtaining the token, you can use it to make requests to your 'https://localhost:7107/api/Values' values -
GET /api/Values
Authorization: Bearer <your_token_here>
The above is a shove in the right direction, you can see way more code than me to adjust this code to wotk for you.