Reputation: 1
My solution has are 4 projects:
In the API project, everything works, but when I include the login in MVC project I get this error:
An unhandled exception occurred while processing the request.
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action configureOptions). Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)
I using the JWT authentication and IdentityUser. When I debug the login in the MVC project, the token is returned, but when the view with Authorize
is opened, I get the error. Can someone help me?
Code for login in my controller in the MVC project:
[HttpPost]
public async Task<IActionResult> Login(Usuarios usuarios)
{
using (var httpClient = new HttpClient())
{
StringContent stringContent = new StringContent(JsonConvert.SerializeObject(usuarios), Encoding.UTF8, "application/json");
using (var response = await httpClient.PostAsync("https://localhost:xxxx/api/Usuarios/Login", stringContent))
{
string token = await response.Content.ReadAsStringAsync();
if (token == "Invalid credentials")
{
ViewBag.Message = "Incorrect UserId or Password!";
return Redirect("~/Usuarios/Login");
}
HttpContext.Session.SetString("JWToken", token);
}
return Redirect("~/ProfileUsers/UserProfile");
}
}
Upvotes: 0
Views: 82
Reputation: 1
You need to create a method Login
in your APS.NET MVC project and indicate the claims' date for your identity user.
Upvotes: 0