Skip to content

Commit c7b7e35

Browse files
authored
Merge pull request #102 from nicosabena/patch-1
Fix listByEmail snippet and added sample for token
2 parents d5bb72d + 1d48756 commit c7b7e35

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,27 @@ try {
247247

248248
## Management API
249249

250-
The implementation is based on the [Management API Docs](https://auth0.com/docs/api/management/v2).
250+
The implementation is based on the [Management API Docs](https://auth0.com/docs/api/management/v2).
251251

252-
Create a `ManagementAPI` instance by providing the domain from the [client dashboard](https://manage.auth0.com/#/clients) and the API Token. Click [here](https://auth0.com/docs/api/management/v2#!/Introduction/Getting_an_API_token) for more information on how to obtain a valid API Token.
252+
Create a `ManagementAPI` instance by providing the domain from the [client dashboard](https://manage.auth0.com/#/clients) and a valid API Token.
253253

254254
```java
255255
ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", "{YOUR_API_TOKEN}");
256256
```
257257

258+
You can use the Authentication API to obtain a token for a previously authorized client:
259+
260+
```java
261+
AuthAPI authAPI = new AuthAPI("{YOUR_DOMAIN}", "{YOUR_CLIENT_ID}", "{YOUR_CLIENT_SECRET}");
262+
AuthRequest authRequest = authAPI.requestToken("https://{YOUR_DOMAIN}/api/v2/");
263+
TokenHolder holder = authRequest.execute();
264+
ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", holder.getAccessToken());
265+
```
266+
267+
(Note that the simplified should have error handling, and ideally cache the obtained token until it expires instead of requesting one access token for each Management API v2 invocation).
268+
269+
Click [here](https://auth0.com/docs/api/management/v2/tokens) for more information on how to obtain API Tokens.
270+
258271
The Management API is divided into different entities. Each of them have the list, create, update, delete and update methods plus a few more if corresponds. The calls are authenticated using the API Token given in the `ManagementAPI` instance creation and must contain the `scope` required by each entity. See the javadoc for details on which `scope` is expected for each call.
259272

260273
* **Client Grants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Client_Grants/get_client_grants). Access the methods by calling `mgmt.clientGrants()`.
@@ -264,7 +277,7 @@ The Management API is divided into different entities. Each of them have the lis
264277
* **Logs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Logs/get_logs). Access the methods by calling `mgmt.logEvents()`.
265278
* **Rules:** See [Docs](https://auth0.com/docs/api/management/v2#!/Rules/get_rules). Access the methods by calling `mgmt.rules()`.
266279
* **User Blocks:** See [Docs](https://auth0.com/docs/api/management/v2#!/User_Blocks/get_user_blocks). Access the methods by calling `mgmt.userBlocks()`.
267-
* **Users:** See [this](https://auth0.com/docs/api/management/v2#!/Users/get_users) and [this](https://auth0.com/docs/api/management/v2#!/Users_By_Email) Docs. Access the methods by calling `mgmt.users()`.
280+
* **Users:** See [this](https://auth0.com/docs/api/management/v2#!/Users/get_users) and [this](https://auth0.com/docs/api/management/v2#!/Users_By_Email) doc. Access the methods by calling `mgmt.users()`.
268281
* **Blacklists:** See [Docs](https://auth0.com/docs/api/management/v2#!/Blacklists/get_tokens). Access the methods by calling `mgmt.blacklists()`.
269282
* **Emails:** See [Docs](https://auth0.com/docs/api/management/v2#!/Emails/get_provider). Access the methods by calling `mgmt.emailProvider()`.
270283
* **Guardian:** See [Docs](https://auth0.com/docs/api/management/v2#!/Guardian/get_factors). Access the methods by calling `mgmt.guardian()`.
@@ -281,14 +294,14 @@ The Management API is divided into different entities. Each of them have the lis
281294
Creates a request to list the Users by Email. This is the preferred and fastest way to query Users by Email, and should be used instead of calling the generic list method with an email query. An API Token with scope `read:users` is needed. If you want the identities.access_token property to be included, you will also need the scope `read:user_idp_tokens`.
282295
You can pass an optional Filter to narrow the results in the response.
283296

284-
`Request<UsersPage> listByEmail(String email, UserFilter filter)`
297+
`Request<List<User>> listByEmail(String email, UserFilter filter)`
285298

286299
Example:
287300
```java
288301
FieldsFilter filter = new FieldsFilter(...);
289-
Request<UsersPage> request = mgmt.users().listByEmail("johndoe@auth0.com", filter);
302+
Request<List<User>> request = mgmt.users().listByEmail("johndoe@auth0.com", filter);
290303
try {
291-
UsersPage response = request.execute();
304+
List<User> response = request.execute();
292305
} catch (APIException exception) {
293306
// api error
294307
} catch (Auth0Exception exception) {

0 commit comments

Comments
 (0)