Hi Pablo,
Thanks for your help. I tried your solution but facing some problems.
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
//spa.UseReactDevelopmentServer(npmScript: "start");
spa.UseProxyToSpaDevelopmentServer("http://localhost:3000/");
}
});
Backend listen on https://localhost:44331/ this URL.
Frontend listen on http://localhost:3000/ this URL.
When I am trying to hit login from http://localhost:3000/ this URL login method is not called.
When I am trying to hit login from https://localhost:44331/ this URL login method is called.
The login method returns ChallengeResult from auth0. I mean return login screen.
public ActionResult Login(string returnUrl = "/")
{
return new ChallengeResult("Auth0", new AuthenticationProperties() { RedirectUri = returnUrl });
}
I do not understand why the login method is not called from http://localhost:3000/
Also, I noticed GetUser method is called from http://localhost:3000/
public ActionResult GetUser()
{
if (User.Identity.IsAuthenticated)
{
var claims = ((ClaimsIdentity)this.User.Identity).Claims.Select(c =>
new { type = c.Type, value = c.Value })
.ToArray();
return Json(new { isAuthenticated = true, claims = claims });
}
return Json(new { isAuthenticated = false });
}
Here is my AuthController.
public class AuthController: Controller
{
public ActionResult Login(string returnUrl = "/")
{
return new ChallengeResult("Auth0", new AuthenticationProperties() { RedirectUri = returnUrl });
}
[Authorize]
public async Task<ActionResult> Logout()
{
await HttpContext.SignOutAsync();
return new SignOutResult("Auth0", new AuthenticationProperties
{
RedirectUri = Url.Action("Index", "Home")
//RedirectUri = Url.Action("Index", "fetch-data")
});
}
public ActionResult GetUser()
{
if (User.Identity.IsAuthenticated)
{
var claims = ((ClaimsIdentity)this.User.Identity).Claims.Select(c =>
new { type = c.Type, value = c.Value })
.ToArray();
return Json(new { isAuthenticated = true, claims = claims });
}
return Json(new { isAuthenticated = false });
}
}
The Login method returned a view and get user method returned data.
Please help me to understand this problem. I want to work BFF application on different ports.
Also, With Authentication login and logout. I set up all callback URLs and logout URL.
Thanks