diff --git a/examples/basic-api/src/Main.php b/examples/basic-api/src/Main.php index 4521d662..7561f0bb 100644 --- a/examples/basic-api/src/Main.php +++ b/examples/basic-api/src/Main.php @@ -27,7 +27,7 @@ public function publicPing(){ public function privatePing(){ - $userData = \Auth0\SDK\Api\ApiUsers::get($this->token, $this->tokenInfo->sub); + $userData = \Auth0\SDK\Api\ApiUsers::get(getenv('AUTH0_DOMAIN'),$this->token, $this->tokenInfo->sub); return array( "status" => 'ok', diff --git a/src/Api/ApiClient.php b/src/API/ApiClient.php similarity index 100% rename from src/Api/ApiClient.php rename to src/API/ApiClient.php diff --git a/src/Api/ApiUsers.php b/src/API/ApiUsers.php similarity index 61% rename from src/Api/ApiUsers.php rename to src/API/ApiUsers.php index b62c8b86..dd512361 100644 --- a/src/Api/ApiUsers.php +++ b/src/API/ApiUsers.php @@ -8,16 +8,22 @@ class ApiUsers { - protected static function getApiV2Client() { + protected static function getApiV2Client($domain) { + + $apiDomain = 'https://login.auth0.com'; + if (strpos($domain, 'eu.auth0.com') !== false) { + $apiDomain = 'https://login.eu.auth0.com'; + } + return new ApiClient(array( - 'domain' => 'https://login.auth0.com', + 'domain' => $apiDomain, 'basePath' => '/api/v2', )); } - public static function get($token, $user_id) { + public static function get($domain, $token, $user_id) { - $user_info = self::getApiV2Client()->get() + $user_info = self::getApiV2Client($domain)->get() ->users($user_id) ->withHeader(new AuthorizationBearer($token)) ->call(); @@ -25,9 +31,9 @@ public static function get($token, $user_id) { return $user_info; } - public static function update($token, $user_id, $data) { + public static function update($domain, $token, $user_id, $data) { - $user_info = self::getApiV2Client()->patch() + $user_info = self::getApiV2Client($domain)->patch() ->users($user_id) ->withHeader(new AuthorizationBearer($token)) ->withHeader(new ContentType('application/json')) @@ -37,9 +43,9 @@ public static function update($token, $user_id, $data) { return $user_info; } - public static function create($token, $data) { + public static function create($domain, $token, $data) { - $user_info = self::getApiV2Client()->post() + $user_info = self::getApiV2Client($domain)->post() ->users() ->withHeader(new AuthorizationBearer($token)) ->withHeader(new ContentType('application/json')) @@ -49,9 +55,9 @@ public static function create($token, $data) { return $user_info; } - public static function search($token, $params) { + public static function search($domain, $token, $params) { - $client = self::getApiV2Client()->post() + $client = self::getApiV2Client($domain)->post() ->users() ->withHeader(new AuthorizationBearer($token)) ->withHeader(new ContentType('application/json')) @@ -64,34 +70,34 @@ public static function search($token, $params) { return $client->call(); } - public static function deleteAll($token) { + public static function deleteAll($domain, $token) { - self::getApiV2Client()->delete() + self::getApiV2Client($domain)->delete() ->users() ->withHeader(new AuthorizationBearer($token)) ->call(); } - public static function delete($token, $user_id) { + public static function delete($domain, $token, $user_id) { - self::getApiV2Client()->delete() + self::getApiV2Client($domain)->delete() ->users($user_id) ->withHeader(new AuthorizationBearer($token)) ->call(); } - public static function getDevices($token, $user_id) { + public static function getDevices($domain, $token, $user_id) { - self::getApiV2Client()->get() + self::getApiV2Client($domain)->get() ->users($user_id) ->devices() ->withHeader(new AuthorizationBearer($token)) ->call(); } - public static function linkAccount($token, $user_id, $post_identities_body) { + public static function linkAccount($domain, $token, $user_id, $post_identities_body) { - return self::getApiV2Client()->post() + return self::getApiV2Client($domain)->post() ->users($user_id) ->devices() ->withHeader(new AuthorizationBearer($token)) @@ -100,9 +106,9 @@ public static function linkAccount($token, $user_id, $post_identities_body) { ->call(); } - public static function unlinkAccount($token, $user_id, $multifactor_provider, $identity) { + public static function unlinkAccount($domain, $token, $user_id, $multifactor_provider, $identity) { - return self::getApiV2Client()->delete() + return self::getApiV2Client($domain)->delete() ->users($user_id) ->addPathVariable($identity) ->identities($multifactor_provider) @@ -110,25 +116,25 @@ public static function unlinkAccount($token, $user_id, $multifactor_provider, $i ->call(); } - public static function unlinkDevice($token, $user_id, $device_id) { - self::getApiV2Client()->delete() + public static function unlinkDevice($domain, $token, $user_id, $device_id) { + self::getApiV2Client($domain)->delete() ->users($user_id) ->devices($device_id) ->withHeader(new AuthorizationBearer($token)) ->call(); } - public static function deleteMultifactorProvider($token, $user_id, $multifactor_provider) { - self::getApiV2Client()->delete() + public static function deleteMultifactorProvider($domain, $token, $user_id, $multifactor_provider) { + self::getApiV2Client($domain)->delete() ->users($user_id) ->multifactor($multifactor_provider) ->withHeader(new AuthorizationBearer($token)) ->call(); } - public static function createEmailVerificationTicket($token, $user_id, $result_url = null) { + public static function createEmailVerificationTicket($domain, $token, $user_id, $result_url = null) { - $request = self::getApiV2Client()->post() + $request = self::getApiV2Client($domain)->post() ->users($user_id) ->tickets() ->email_verification() @@ -145,7 +151,7 @@ public static function createEmailVerificationTicket($token, $user_id, $result_u } - public static function createPasswordChangeTicket($token, $user_id, $new_password, $result_url = null) { + public static function createPasswordChangeTicket($domain, $token, $user_id, $new_password, $result_url = null) { $body = array( 'new_password' => $new_password @@ -155,7 +161,7 @@ public static function createPasswordChangeTicket($token, $user_id, $new_passwor $body['result_url'] = $result_url; } - return self::getApiV2Client()->post() + return self::getApiV2Client($domain)->post() ->users($user_id) ->tickets() ->email_verification() diff --git a/src/Api/Header/Authorization/AuthorizationBearer.php b/src/API/Header/Authorization/AuthorizationBearer.php similarity index 100% rename from src/Api/Header/Authorization/AuthorizationBearer.php rename to src/API/Header/Authorization/AuthorizationBearer.php diff --git a/src/Api/Header/ContentType.php b/src/API/Header/ContentType.php similarity index 100% rename from src/Api/Header/ContentType.php rename to src/API/Header/ContentType.php diff --git a/src/Api/Header/Header.php b/src/API/Header/Header.php similarity index 100% rename from src/Api/Header/Header.php rename to src/API/Header/Header.php diff --git a/src/Api/RequestBuilder.php b/src/API/RequestBuilder.php similarity index 100% rename from src/Api/RequestBuilder.php rename to src/API/RequestBuilder.php diff --git a/src/Api/TokenGenerator.php b/src/API/TokenGenerator.php similarity index 100% rename from src/Api/TokenGenerator.php rename to src/API/TokenGenerator.php diff --git a/src/Auth0.php b/src/Auth0.php index 1871a402..76237238 100644 --- a/src/Auth0.php +++ b/src/Auth0.php @@ -253,7 +253,7 @@ private function exchangeCode() { $token = Auth0JWT::decode($id_token, $this->client_id, $this->client_secret); - $user = ApiUsers::get($id_token, $token->user_id); + $user = ApiUsers::get($this->domain, $id_token, $token->user_id); $this->setUser($user); @@ -298,7 +298,7 @@ public function getUserInfo() { */ public function updateUserMetadata($metadata) { - $user = ApiUsers::update($this->getIdToken(), $this->user["user_id"], array('user_metadata' => $metadata)); + $user = ApiUsers::update($this->domain, $this->getIdToken(), $this->user["user_id"], array('user_metadata' => $metadata)); $this->setUser($user); }