Sasa
Sasa

Reputation: 563

php auth0 api update app_data

I am trying to use auth0 api for php. I strated with this examples: enter link description here

Every time when I start I got error that I'm calling non-defined class in dotenv-autoloader (Dotenv::load(__DIR__);). I avoid this and I wrote manually parameter. After that I can create, delete user, change user_metadata, but I can't change app_matadata. Always got same error: {"statusCode":401,"error":"Unauthorized","message":"Missing authentication"}

Can someone help me with this issue?

Thanks.

Upvotes: 0

Views: 400

Answers (1)

Germán Lena
Germán Lena

Reputation: 887

what error did you get with Dotenv?

3 things might happened:

  • it was not installed (which is weird since it is a dependency in the composer.json file)
  • there was no .env file with the configuration
  • the .env file had the wrong format

Anyway, if you set the configuration manually is enough.

About the app_metadata how are you updating it?

this snippet should work:

require __DIR__ . '/vendor/autoload.php';

use Auth0\SDK\Auth0Api;

$token = "eyJhbGciO....eyJhdWQiOiI....1ZVDisdL...";
$domain = "account.auth0.com";
$user_id = 'auth0|123...';

$auth0Api = new Auth0Api($token, $domain);

$usersList = $auth0Api->users->update( $user_id, [ "app_metadata" => [ "some_attribute" => "some_value" ] ]);

var_dump($usersList);

One important thing, to update the app_metadata you need an api token with the update:users_app_metadata scope, you can't use the user token for it.

Upvotes: 2

Related Questions