Go Directly to Sign Up Page

Where do you place “screen_hint=signup” in the quickstart app in the php code in order to go straight to the signup page instead of login?

Hi @matthewyoung245

Welcome to the Auth0 Community!

In order to add “screen_hint=signup” to your PHP quickstart application you need to extend this code snippet:

// 👆 We're continuing from the steps above. Append this to your index.php file.

Route::add('/login', function() use ($auth0) {
    // It's a good idea to reset user sessions each time they go to login to avoid "invalid state" errors, should they hit network issues or other problems that interrupt a previous login process:
    $auth0->clear();

    // Finally, set up the local application session, and redirect the user to the Auth0 Universal Login Page to authenticate.
    header("Location: " . $auth0->login(ROUTE_URL_CALLBACK, null, ['screen_hint' => 'signup']));
    exit;
});

Let me know if this helped you

Thanks, and have a great day!

Dawid

@dawid.matuszczyk

I am using this quickstart app:

Which file would that go in?

I’m not an PHP expert but you should integrate it into the login function → https://github.com/auth0-samples/auth0-php-web-app/blob/9dc7fbafb13fd8da81c290534aef78d3d53706f3/app/src/Application.php#L206
This is the quickstart guide I mentioned in the solution response, mentioned app is based on this guide → Auth0 PHP SDK Quickstarts: Login

@dawid.matuszczyk

I tried this and didn’t work.

Hi @matthewyoung245,

Sorry for not enough explanation, screen_hint => signup needs to be passed as a login parameter, not getUri

$router->redirect($this->sdk->login($router->getUri('/callback', ''), ['screen_hint' => 'signup']));

Can you try this?

Thanks
Dawid

@dawid.matuszczyk

This worked after adjusting your code a little bit!

Do you know what this error means when trying to edit a users metadata?

{“statusCode”:400,“error”:“Bad Request”,“message”:“Payload validation error: ‘Missing required property: connection’.”,“errorCode”:“invalid_body”}

This is the link I am using to help me with this using the PHP format.

https://auth0.com/docs/manage-users/user-accounts/metadata/manage-metadata-api#update-user-metadata

Hi @matthewyoung245

Can you share the code snippet that is triggering this error for you?

If you are updating a user’s email, email_verified, phone_number, phone_verified, username or password of a secondary identity, you must specify the connection property. Auth0 Management API v2

@evansims

Below is the code after copying it straight from the link I posted up above. How do I specify the connection property in the code?

$curl3456 = curl_init();

        curl_setopt_array($curl3456, [
        CURLOPT_URL => "https://mydomain/api/v2/users",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "{\"email\": \"testing893828@outlook.com\", \"user_metadata\": {\"hobby\": \"surfing\"}, \"app_metadata\": {\"plan\": \"full\"}}",
        CURLOPT_HTTPHEADER => [
            "authorization: Bearer ".$tokendecode,
            "content-type: application/json"
        ],
        ]);

        $response34 = curl_exec($curl3456);
        $err34 = curl_error($curl3456);

        curl_close($curl3456);

        if ($err34) {
        echo "cURL Error #:" . $err34;
        } else {
        echo $response34;
        }

Hi @matthewyoung245

Thanks for sharing that code!

By issuing a POST request to the /api/v2/users endpoint you’re actually creating a new user. I inferred by asking do you know what this error means when trying to edit a users metadata? to mean updating an existing user. Can you clarify if you’re trying to use the Management API to create a new user or update an existing one?

  • When creating a user, a connection must always be provided.
  • When updating a user, a connection is required if you are updating a user’s email , email_verified , phone_number , phone_verified , username or password of a secondary identity.

In either case, to provide a connection parameter you need to include it in your JSON-formatted post body — in your code, that’s currently defined as this:

CURLOPT_POSTFIELDS => "{\"email\": \"testing893828@outlook.com\", \"user_metadata\": {\"hobby\": \"surfing\"}, \"app_metadata\": {\"plan\": \"full\"}}",

To avoid errors, I would recommend changing this to use json_encode() instead:

CURLOPT_POSTFIELDS => json_encode([
  'email' => 'testing893828@outlook.com',
  'user_metadata' => [
    'hobby' => 'surfing',
  ],
  'app_metadata' => [
    'plan' => 'full',
  ],
]);

Then add your connection as a new entry in the array:

CURLOPT_POSTFIELDS => json_encode([
  'connection' => '...',
  'email' => 'testing893828@outlook.com',
  'user_metadata' => [
    'hobby' => 'surfing',
  ],
  'app_metadata' => [
    'plan' => 'full',
  ],
]);

Thank you @evansims

Yes you are correct in that I am just trying to update a user.

Where do I get the connection information? Is it in my Auth0 account under databases?

@matthewyoung245 No problem!

You can find connection IDs from their entries in the Connections page, in your Auth0 Dashboard. For example, https://manage.auth0.com/#/connections/database

Select a connection, and beneath it’s name you’ll see it’s identifier — a string beginning with con_.

Screenshot 2023-08-01 at 11.15.19 AM

That’s the value you’d want to provide for the connection.

However, if you’re only looking to update an existing user’s metadata you don’t need to provide a connection identifier.

If that is the case, the user update example from the URL you linked will work fine:

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://{yourDomain}/api/v2/users/user_id",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => json_encode([
    'user_metadata' => [
      'addresses' => [
        '123 Main Street, Anytown, ST 12345',
      ],
    ],
  ]),
  CURLOPT_HTTPHEADER => [
    "authorization: Bearer ABCD",
    "content-type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Thank you @evansims !

All this was super helpful! Seeing the actual code definitely and the way you broke it down made the difference for me in understanding it all.

Are you the PHP person to reach out to with questions?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.