I have an issue where redirecting user after authentication is not working properly
currently testing in local environment
when user first goes to login page (http://localhost:44394/acount/login
), Auth0 universal login page will appear
// AccountController.cs
public async Task<ActionResult> Login() {
var domain = ProLib.AppSettings.Get<string>("Auth0_Domain");
var clientId = ProLib.AppSettings.Get<string>("Auth0_ClientId");
var redirectUri = ProLib.AppSettings.Get<string>("Auth0_RedirectUri");
var root = "http://localhost:44394/";
var client = new AuthenticationApiClient(domain);
var authorizationUrl = client.BuildAuthorizationUrl()
.WithResponseType(AuthorizationResponseType.Code)
.WithClient(clientId)
.WithConnection("Username-Password-Authentication")
.WithRedirectUrl(root + redirectUri)
.WithScope("openid offline_access profile email")
.Build();
Console.WriteLine(authorizationUrl);
return Redirect(authorizationUrl.AbsoluteUri);
}
after user inputs credentials, is redirected to http://localhost:44394/Account/Callback?code=j1-zo7ZEZ7kVEPlkYyxZfTfuCoR5VMn1xeeeeeeeeee
and below is my code to handle after redirection
// AccountController.cs
public async Task<IActionResult> Callback(string code)
{
var domain = ProLib.AppSettings.Get<string>("Auth0_Domain");
var clientId = ProLib.AppSettings.Get<string>("Auth0_ClientId");
var clientSecret = ProLib.AppSettings.Get<string>("Auth0_ClientSecret");
var redirectUri = ProLib.AppSettings.Get<string>("Auth0_RedirectUri");
var root = "http://localhost:44394/";
var client = new AuthenticationApiClient(domain);
var request = new AuthorizationCodeTokenRequest()
{
ClientId = clientId,
ClientSecret = clientSecret,
Code = code,
RedirectUri = root + redirectUri
};
return RedirectToAction("Index", "Home", new { area = "App" });
}
catch (Exception)
{
return RedirectToAction("Index", "Home", new { area = "App" });
}
}
and I got the error as below
This site can’t be reachedThe connection was reset.
callback url http://localhost:44394/account/callback
is whitelisted and not sure how to handle further logic to send auth code and get accesstoken