Login using Custom UI in ASP.NET Core

Hi All

I am using .NET core to try to login. I have the following code:

 public static bool Login(LoginViewModel vm, Auth0 auth0Options)
        {
            var client = new RestClient($"https://{auth0Options.Domain}/dbconnections/login/");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json",
                "{\"client_id\": \"" + auth0Options.ClientId +
                "\",\"tenant\": \"" + auth0Options.ClientId +
                "\",\"email\": \"" + vm.Email +
                "\",\"password\": \"" + vm.Password +
                "\",\"connection\": \"Username-Password-Authentication" +
                "\"}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            return response.IsSuccessful;
        }

Instead of getting signed in, I get IsSuccessful = false. The response body is:

{
    "name": "BadRequestError",
    "code": "missing_property",
    "description": "tenant must be specified",
    "statusCode": 400
}

What am I doing wrong?

Thanks and Regards
Zawar

Hello… does anyone answer questions around here? Anyone?

:wave: @zawarq the clientid is different from your tenant name, and you havae auth0Options.ClientId for both client_id and tenant. ClientID is the application ID found here https://manage.auth0.com/#/applications and the tenant name is in the top right corner when you are in manage.auth0.com . The reason you are getting an error is because you did not put the correct tenant name in the parameters.

1 Like

Hi Kim

Thank you for your help :grin:. I modified the code to as follows:

            var client = new RestClient($"https://{auth0Options.Domain}/dbconnections/login/");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/json");

            request.AddParameter("application/json",
                "{\"client_id\": \"" + auth0Options.ClientId +
                "\",\"tenant\": \"" + auth0Options.Tenant +
                "\",\"username\": \"" + vm.Email +
                "\",\"password\": \"" + vm.Password +
                "\",\"connection\": \"Username-Password-Authentication" +
                "\"}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            return response.IsSuccessful;

and now I get this error:

{"name":"ValidationError","code":"invalid_user_password","description":"Wrong email or password.","statusCode":400}

However I am sure of the user name and password as I they work fine with the Lock widget. Note that I also tried to change “username” to “email” and to “username/email” in the .AddParameter call.

Kindly help.

Regards
Zawar

Bump.

We really need working examples for .NET for login and sign up (I already got signout and password change working).

Hey there!

Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience!

Do you still require further assistance from us?

It’s important to note that the dbconnections/login is a private API endpoint and can be modified without notice at any time or as needed.