Auth0 Home Blog Docs

Want to configure hosted login page via an ASP.NET Core web app


#1

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.

Sign In with Auth0

#2

Also curious to know if this can be done. I’ve considered using an XHR in the hosted page to go back to my site to read the config.


#3

One option could be to use login_hint - though it’s not really meant for this usage but can be used.

Something like this:

public async Task Login(string returnUrl = “/”)
{
await HttpContext.ChallengeAsync(“Auth0”, new AuthenticationProperties() {new Dictionary<string,string>(){ {“login_hint”,“signup”}
});

HTH,
Zulfiqar


#4

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”);

        await HttpContext.ChallengeAsync("Auth0", props);
    }

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?

Appreciate any help.
Cheers John.


#5

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


#6

No - it’s not included.

Here is network trace:

Here is debugging info from controller:

Hope this helps.


#7

hmm, that’s strange. Apparently parameters is the 2nd argument in AuthenticationProperties. Can you try following please?

await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties(null,new Dictionary<string,object>(){ {"prompt","signup"} }));

Thanks,
Zulfiqar


#8

Thanks Zulfiqar for continuing to help.

I’m not a C# expert so I may be missing something.

If I try your code, I get an error as follows:

ie saying that ‘AuthenticationProperties’ does not contain a constructor that takes 2 arguments.

If we then examine the AuthenticationProperties class we see the following:
image

If I try something like:

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; }

Cheers, John