-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-3705] Redesign readme to match new style (#751)
Co-authored-by: Frederik Prijck <[email protected]>
- Loading branch information
1 parent
0cc599e
commit 7c3e31a
Showing
3 changed files
with
143 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Examples | ||
|
||
## Automatic Management API Token Retrieval | ||
|
||
To **automatically** obtain a Management API token via the ManagementClient, you can specify the parameters `clientId`, `clientSecret` (use a Non Interactive Client) and optionally `scope`. | ||
Behind the scenes the Client Credentials Grant is used to obtain the `access_token` and is by default cached for the duration of the returned `expires_in` value. | ||
|
||
```js | ||
var ManagementClient = require('auth0').ManagementClient; | ||
var auth0 = new ManagementClient({ | ||
domain: '{YOUR_ACCOUNT}.auth0.com', | ||
clientId: '{YOUR_NON_INTERACTIVE_CLIENT_ID}', | ||
clientSecret: '{YOUR_NON_INTERACTIVE_CLIENT_SECRET}', | ||
scope: 'read:users update:users', | ||
}); | ||
``` | ||
|
||
> Make sure your `clientId` is allowed to request tokens from Management API in [Auth0 Dashboard](https://manage.auth0.com/#/apis) | ||
### Obtaining Management API Token from Node.js backend | ||
|
||
To obtain a Management API token from your node backend, you can use Client Credentials Grant using your registered Auth0 Non Interactive Clients | ||
|
||
```js | ||
var AuthenticationClient = require('auth0').AuthenticationClient; | ||
|
||
var auth0 = new AuthenticationClient({ | ||
domain: '{YOUR_ACCOUNT}.auth0.com', | ||
clientId: '{CLIENT_ID}', | ||
clientSecret: '{CLIENT_SECRET}', | ||
}); | ||
|
||
auth0.clientCredentialsGrant( | ||
{ | ||
audience: 'https://{YOUR_ACCOUNT}.auth0.com/api/v2/', | ||
scope: '{MANAGEMENT_API_SCOPES}', | ||
}, | ||
function (err, response) { | ||
if (err) { | ||
// Handle error. | ||
} | ||
console.log(response.access_token); | ||
} | ||
); | ||
``` | ||
|
||
### Promises and callback support | ||
|
||
All methods can be used with promises or callbacks, when a callback argument is provided no promise will be returned. | ||
|
||
```js | ||
// Using callbacks. | ||
management.getUsers(function (err, users) { | ||
if (err) { | ||
// handle error. | ||
} | ||
console.log(users); | ||
}); | ||
|
||
// Using promises. | ||
management | ||
.getUsers() | ||
.then(function (users) { | ||
console.log(users); | ||
}) | ||
.catch(function (err) { | ||
// Handle error. | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Frequently Asked Questions | ||
|
||
Below are a number of questions or issues that have arisen from using the SDK. | ||
|
||
## Does this library have type definitions? | ||
|
||
The types for this library are currently maintained by the community at [Definitely Typed](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/auth0). The team is planning taking ownership of this library as discussed in https://github.com/auth0/node-auth0/issues/572. | ||
|
||
### Getting `Error: Can't resolve 'superagent-proxy'` when bundling with Webpack | ||
|
||
We have a dependency on `rest-facade` which `require`s but doesn't include `superagent-proxy`. This SDK doesn't support proxies, so this dependency is not required. To workaround this you can add the following to your `webpack.config.js`: | ||
|
||
``` | ||
resolve: { | ||
alias: { | ||
'superagent-proxy': false | ||
} | ||
} | ||
``` | ||
|
||
Or install `superagent-proxy` yourself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters