Skip to content

Commit

Permalink
Merge pull request #28 from auth0/1.x.x-dev
Browse files Browse the repository at this point in the history
Fix create client api call + new create user example
  • Loading branch information
glena committed Jul 27, 2015
2 parents e1aabd5 + 8562cb2 commit 15d4192
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ The version 1.x of the PHP SDK now works with the Auth API v2 which adds lots of

>***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).
## Examples

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.
You just need to create a `.env` file with the following information:

```
AUTH0_CLIENT_SECRET=YOUR_APP_SECRET
AUTH0_CLIENT_ID=YOU_APP_CLIENT
AUTH0_DOMAIN=YOUR_DOMAIN.auth0.com
AUTH0_CALLBACK_URL=http://localhost:3000/index.php
AUTH0_APPTOKEN=A_VALID_APPTOKEN_WITH_CREATE_USER_SCOPE
```

You will get your app client and secret from your Auth0 app you had created.
The auth0 domain, is the one you pick when you created your auth0 account.
You need to set this callback url in your app allowed callbacks.
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)

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.

```
$ composer install
$ php -S localhost:3000
```

## Migration guide from 0.6.6

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.
Expand Down
39 changes: 39 additions & 0 deletions examples/basic-oauth/create_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

if (isset($_REQUEST['create'])) {

$app_token = getenv('AUTH0_APPTOKEN');
$domain = getenv('AUTH0_DOMAIN');

$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$color = $_REQUEST['color'];

echo '<pre>';
var_dump(\Auth0\SDK\API\ApiUsers::create($domain, $app_token, array(
'email' => $email,
'password' => $password,
'connection' => 'Username-Password-Authentication',
'user_metadata' => array(
'color' => $color,
)
)));
echo '</pre>';
}
?>


<form action="?create-user" method="POST">

<label for="email">Email</label>
<input type="email" name="email" id="email" />

<label for="password">Password</label>
<input type="password" name="password" id="password" />

<label for="color">Color</label>
<input type="color" name="color" id="color" />

<input type="submit" name="create" value="Create" />

</form>
6 changes: 6 additions & 0 deletions examples/basic-oauth/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

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

if (isset($_REQUEST['create-user'])) {
require 'create_user.php';
exit;
}


if ($userInfo) require 'logeduser.php';


Expand Down
1 change: 1 addition & 0 deletions examples/basic-oauth/logeduser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<a href="?logout">Logout</a>
<a href="?update-metadata">Update Metadata</a>
<a href="?create-user">Create User</a>


<?php
Expand Down
3 changes: 2 additions & 1 deletion src/API/ApiClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public static function create($domain, $token, $data) {

$info = self::getApiV2Client($domain, $token)->post()
->clients()
->withHeader(new AuthorizationBearer($token))
->withHeader(new ContentType('application/json'))
->withBody(json_encode($data))
->call();
->dump();

return $info;
}
Expand Down

0 comments on commit 15d4192

Please sign in to comment.