Skip to content

Commit

Permalink
Merge pull request #11 from auth0/1.x.x-dev
Browse files Browse the repository at this point in the history
Fix EU api calls and autoloading issue
  • Loading branch information
glena committed May 13, 2015
2 parents 15495b5 + 8500eb2 commit b65ed20
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/basic-api/src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.
62 changes: 34 additions & 28 deletions src/Api/ApiUsers.php → src/API/ApiUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@

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

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'))
Expand All @@ -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'))
Expand All @@ -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'))
Expand All @@ -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))
Expand All @@ -100,35 +106,35 @@ 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)
->withHeader(new AuthorizationBearer($token))
->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()
Expand All @@ -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
Expand All @@ -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()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b65ed20

Please sign in to comment.