I want my hosted login page to be configurable - essentially I want to pass the initialScreen parameter to configure the login page.
I’ve seen an example using JS, however I’m using ASP.NET Core 2 and I can’t find any such example.
I’m thinking that in my Login method in my controller I can somehow pass the parameter:
public async Task Login(string returnUrl = “/”)
{
await HttpContext.ChallengeAsync(“Auth0”, new AuthenticationProperties() { RedirectUri = returnUrl });
}
Then, in my hosted login page I can pickup the parameter. In the HTML page below, I have currently hard-coded initialScreen: ‘signUp’ when configuring lock.
I want ‘signUp’ to be passed as a parameter.
Thanks for responding and for the login_hint idea. However, I still have an issue.
I’ve tried using login_hint.
In the controller code I did:
public async Task Login(string returnUrl = “/”)
{
var props = new AuthenticationProperties { RedirectUri = returnUrl };
props.Items.Add(“login_hint”, “signUp”);
Then on the hosted login page, I tried to retrieve the parameter login_hint by examining config.extraParams.
However, extraParams did not contain login_hint.
So, not sure what’s going on?
a) did I pass the new parameter “login_hint” incorrectly from my controller?
b) was I correct in looking for “login_hint” in config.extraParams?
Can you please check network trace in chrome to see if login_hint is included in /authorize request to auth0? If it’s include - it should be available in extraParams
notice the message Property or indexer ‘AuthenticationProperties.Items’ cannot be assigned to – it is read only’
which corresponds to the class definition of Items ( get; }
I wound up using a cookie and custom domains to read the setting from the hosted login page. This will only work if your auth challenge and hosted page are on the same root domain. Here the auth challenge is issued at www.example.com and the login page is hosted at login.example.com.
[HttpGet("login-auth0-redirect")]
public IActionResult LoginAuth0Redirect(string mode = "login")
{
Response.Cookies.Append("auth0-mode", mode, new CookieOptions
{
Domain = "example.com",
Secure = true,
Expires = DateTimeOffset.UtcNow.AddMinutes(5)
});
return new ChallengeResult("Auth0",
new AuthenticationProperties
{
RedirectUri = Url.Action("Auth0Callback", "Account"),
});
}
You mention that Auth Challenge and login page must be in same domain.
My scenario at the moment (in development phase) has Auth Challenge on a general Azure page (azurewebsites.net domain) and my login page is hosted using the auth0.com domain.
Does that mean that your solution won’t work for me?
I was able to pass the prompt parameter across with this code in the controller
[AllowAnonymous]
[Route(“login”)]
public async Task LogIn(string returnUrl = “/”)
{
var authenticationProperties = new AuthenticationProperties { RedirectUri = returnUrl };
authenticationProperties.SetParameter(“prompt”, “login”);
await HttpContext.ChallengeAsync(“Auth0”, authenticationProperties);
}
I can then access the value in the javascript using:
config.extraParams.prompt