Skip to content

Commit b65ed20

Browse files
committed
Merge pull request #11 from auth0/1.x.x-dev
Fix EU api calls and autoloading issue
2 parents 15495b5 + 8500eb2 commit b65ed20

File tree

9 files changed

+37
-31
lines changed

9 files changed

+37
-31
lines changed

examples/basic-api/src/Main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function publicPing(){
2727

2828
public function privatePing(){
2929

30-
$userData = \Auth0\SDK\Api\ApiUsers::get($this->token, $this->tokenInfo->sub);
30+
$userData = \Auth0\SDK\Api\ApiUsers::get(getenv('AUTH0_DOMAIN'),$this->token, $this->tokenInfo->sub);
3131

3232
return array(
3333
"status" => 'ok',
File renamed without changes.

src/Api/ApiUsers.php renamed to src/API/ApiUsers.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@
88

99
class ApiUsers {
1010

11-
protected static function getApiV2Client() {
11+
protected static function getApiV2Client($domain) {
12+
13+
$apiDomain = 'https://login.auth0.com';
14+
if (strpos($domain, 'eu.auth0.com') !== false) {
15+
$apiDomain = 'https://login.eu.auth0.com';
16+
}
17+
1218
return new ApiClient(array(
13-
'domain' => 'https://login.auth0.com',
19+
'domain' => $apiDomain,
1420
'basePath' => '/api/v2',
1521
));
1622
}
1723

18-
public static function get($token, $user_id) {
24+
public static function get($domain, $token, $user_id) {
1925

20-
$user_info = self::getApiV2Client()->get()
26+
$user_info = self::getApiV2Client($domain)->get()
2127
->users($user_id)
2228
->withHeader(new AuthorizationBearer($token))
2329
->call();
2430

2531
return $user_info;
2632
}
2733

28-
public static function update($token, $user_id, $data) {
34+
public static function update($domain, $token, $user_id, $data) {
2935

30-
$user_info = self::getApiV2Client()->patch()
36+
$user_info = self::getApiV2Client($domain)->patch()
3137
->users($user_id)
3238
->withHeader(new AuthorizationBearer($token))
3339
->withHeader(new ContentType('application/json'))
@@ -37,9 +43,9 @@ public static function update($token, $user_id, $data) {
3743
return $user_info;
3844
}
3945

40-
public static function create($token, $data) {
46+
public static function create($domain, $token, $data) {
4147

42-
$user_info = self::getApiV2Client()->post()
48+
$user_info = self::getApiV2Client($domain)->post()
4349
->users()
4450
->withHeader(new AuthorizationBearer($token))
4551
->withHeader(new ContentType('application/json'))
@@ -49,9 +55,9 @@ public static function create($token, $data) {
4955
return $user_info;
5056
}
5157

52-
public static function search($token, $params) {
58+
public static function search($domain, $token, $params) {
5359

54-
$client = self::getApiV2Client()->post()
60+
$client = self::getApiV2Client($domain)->post()
5561
->users()
5662
->withHeader(new AuthorizationBearer($token))
5763
->withHeader(new ContentType('application/json'))
@@ -64,34 +70,34 @@ public static function search($token, $params) {
6470
return $client->call();
6571
}
6672

67-
public static function deleteAll($token) {
73+
public static function deleteAll($domain, $token) {
6874

69-
self::getApiV2Client()->delete()
75+
self::getApiV2Client($domain)->delete()
7076
->users()
7177
->withHeader(new AuthorizationBearer($token))
7278
->call();
7379
}
7480

75-
public static function delete($token, $user_id) {
81+
public static function delete($domain, $token, $user_id) {
7682

77-
self::getApiV2Client()->delete()
83+
self::getApiV2Client($domain)->delete()
7884
->users($user_id)
7985
->withHeader(new AuthorizationBearer($token))
8086
->call();
8187
}
8288

83-
public static function getDevices($token, $user_id) {
89+
public static function getDevices($domain, $token, $user_id) {
8490

85-
self::getApiV2Client()->get()
91+
self::getApiV2Client($domain)->get()
8692
->users($user_id)
8793
->devices()
8894
->withHeader(new AuthorizationBearer($token))
8995
->call();
9096
}
9197

92-
public static function linkAccount($token, $user_id, $post_identities_body) {
98+
public static function linkAccount($domain, $token, $user_id, $post_identities_body) {
9399

94-
return self::getApiV2Client()->post()
100+
return self::getApiV2Client($domain)->post()
95101
->users($user_id)
96102
->devices()
97103
->withHeader(new AuthorizationBearer($token))
@@ -100,35 +106,35 @@ public static function linkAccount($token, $user_id, $post_identities_body) {
100106
->call();
101107
}
102108

103-
public static function unlinkAccount($token, $user_id, $multifactor_provider, $identity) {
109+
public static function unlinkAccount($domain, $token, $user_id, $multifactor_provider, $identity) {
104110

105-
return self::getApiV2Client()->delete()
111+
return self::getApiV2Client($domain)->delete()
106112
->users($user_id)
107113
->addPathVariable($identity)
108114
->identities($multifactor_provider)
109115
->withHeader(new AuthorizationBearer($token))
110116
->call();
111117
}
112118

113-
public static function unlinkDevice($token, $user_id, $device_id) {
114-
self::getApiV2Client()->delete()
119+
public static function unlinkDevice($domain, $token, $user_id, $device_id) {
120+
self::getApiV2Client($domain)->delete()
115121
->users($user_id)
116122
->devices($device_id)
117123
->withHeader(new AuthorizationBearer($token))
118124
->call();
119125
}
120126

121-
public static function deleteMultifactorProvider($token, $user_id, $multifactor_provider) {
122-
self::getApiV2Client()->delete()
127+
public static function deleteMultifactorProvider($domain, $token, $user_id, $multifactor_provider) {
128+
self::getApiV2Client($domain)->delete()
123129
->users($user_id)
124130
->multifactor($multifactor_provider)
125131
->withHeader(new AuthorizationBearer($token))
126132
->call();
127133
}
128134

129-
public static function createEmailVerificationTicket($token, $user_id, $result_url = null) {
135+
public static function createEmailVerificationTicket($domain, $token, $user_id, $result_url = null) {
130136

131-
$request = self::getApiV2Client()->post()
137+
$request = self::getApiV2Client($domain)->post()
132138
->users($user_id)
133139
->tickets()
134140
->email_verification()
@@ -145,7 +151,7 @@ public static function createEmailVerificationTicket($token, $user_id, $result_u
145151

146152
}
147153

148-
public static function createPasswordChangeTicket($token, $user_id, $new_password, $result_url = null) {
154+
public static function createPasswordChangeTicket($domain, $token, $user_id, $new_password, $result_url = null) {
149155

150156
$body = array(
151157
'new_password' => $new_password
@@ -155,7 +161,7 @@ public static function createPasswordChangeTicket($token, $user_id, $new_passwor
155161
$body['result_url'] = $result_url;
156162
}
157163

158-
return self::getApiV2Client()->post()
164+
return self::getApiV2Client($domain)->post()
159165
->users($user_id)
160166
->tickets()
161167
->email_verification()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/Auth0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private function exchangeCode() {
253253

254254
$token = Auth0JWT::decode($id_token, $this->client_id, $this->client_secret);
255255

256-
$user = ApiUsers::get($id_token, $token->user_id);
256+
$user = ApiUsers::get($this->domain, $id_token, $token->user_id);
257257

258258
$this->setUser($user);
259259

@@ -298,7 +298,7 @@ public function getUserInfo() {
298298
*/
299299
public function updateUserMetadata($metadata) {
300300

301-
$user = ApiUsers::update($this->getIdToken(), $this->user["user_id"], array('user_metadata' => $metadata));
301+
$user = ApiUsers::update($this->domain, $this->getIdToken(), $this->user["user_id"], array('user_metadata' => $metadata));
302302

303303
$this->setUser($user);
304304
}

0 commit comments

Comments
 (0)