Skip to content

Commit 15d4192

Browse files
committed
Merge pull request #28 from auth0/1.x.x-dev
Fix create client api call + new create user example
2 parents e1aabd5 + 8562cb2 commit 15d4192

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ The version 1.x of the PHP SDK now works with the Auth API v2 which adds lots of
2121

2222
>***Note:*** API V2 restrict the access to the endpoints via scopes. By default, the user token has granted certain scopes that let update the user metadata but not the root attributes nor app_metadata. To update this information and access another endpoints, you need an special token with this scopes granted. For more information about scopes, check [the API v2 docs](https://auth0.com/docs/apiv2Changes#6).
2323
24+
## Examples
25+
26+
Check the [basic-oauth](https://github.com/auth0/auth0-PHP/tree/master/examples/basic-oauth) example to see a quick demo on how the sdk works.
27+
You just need to create a `.env` file with the following information:
28+
29+
```
30+
AUTH0_CLIENT_SECRET=YOUR_APP_SECRET
31+
AUTH0_CLIENT_ID=YOU_APP_CLIENT
32+
AUTH0_DOMAIN=YOUR_DOMAIN.auth0.com
33+
AUTH0_CALLBACK_URL=http://localhost:3000/index.php
34+
AUTH0_APPTOKEN=A_VALID_APPTOKEN_WITH_CREATE_USER_SCOPE
35+
```
36+
37+
You will get your app client and secret from your Auth0 app you had created.
38+
The auth0 domain, is the one you pick when you created your auth0 account.
39+
You need to set this callback url in your app allowed callbacks.
40+
The app token is used in the 'create user' page and needs `create:users` scope. To create one, you need to use the token generator in the [API V2 documentation page](https://auth0.com/docs/apiv2)
41+
42+
To run the example, you need composer (the PHP package manager) installed (you can find more info about composer [here](https://getcomposer.org/doc/00-intro.md)) and run the following commands on the same folder than the code.
43+
44+
```
45+
$ composer install
46+
$ php -S localhost:3000
47+
```
48+
2449
## Migration guide from 0.6.6
2550

2651
1. First is important to read the [API v2 changes document](https://auth0.com/docs/apiv2Changes) to catch up the latest changes to the API.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
if (isset($_REQUEST['create'])) {
4+
5+
$app_token = getenv('AUTH0_APPTOKEN');
6+
$domain = getenv('AUTH0_DOMAIN');
7+
8+
$email = $_REQUEST['email'];
9+
$password = $_REQUEST['password'];
10+
$color = $_REQUEST['color'];
11+
12+
echo '<pre>';
13+
var_dump(\Auth0\SDK\API\ApiUsers::create($domain, $app_token, array(
14+
'email' => $email,
15+
'password' => $password,
16+
'connection' => 'Username-Password-Authentication',
17+
'user_metadata' => array(
18+
'color' => $color,
19+
)
20+
)));
21+
echo '</pre>';
22+
}
23+
?>
24+
25+
26+
<form action="?create-user" method="POST">
27+
28+
<label for="email">Email</label>
29+
<input type="email" name="email" id="email" />
30+
31+
<label for="password">Password</label>
32+
<input type="password" name="password" id="password" />
33+
34+
<label for="color">Color</label>
35+
<input type="color" name="color" id="color" />
36+
37+
<input type="submit" name="create" value="Create" />
38+
39+
</form>

examples/basic-oauth/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
if (isset($_REQUEST['update-metadata'])) require 'update-metadata.php';
2424

25+
if (isset($_REQUEST['create-user'])) {
26+
require 'create_user.php';
27+
exit;
28+
}
29+
30+
2531
if ($userInfo) require 'logeduser.php';
2632

2733

examples/basic-oauth/logeduser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<a href="?logout">Logout</a>
22
<a href="?update-metadata">Update Metadata</a>
3+
<a href="?create-user">Create User</a>
34

45

56
<?php

src/API/ApiClients.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ public static function create($domain, $token, $data) {
7373

7474
$info = self::getApiV2Client($domain, $token)->post()
7575
->clients()
76+
->withHeader(new AuthorizationBearer($token))
7677
->withHeader(new ContentType('application/json'))
7778
->withBody(json_encode($data))
78-
->call();
79+
->dump();
7980

8081
return $info;
8182
}

0 commit comments

Comments
 (0)