Allow to update the Management API token#141
Conversation
README.md
Outdated
|
|
||
| Click [here](https://auth0.com/docs/api/management/v2/tokens) for more information on how to obtain API Tokens. | ||
|
|
||
| In the event of token expiration a new one can be set to an existing `ManagementAPI` instance by calling the `setApiToken` method with the new token. |
There was a problem hiding this comment.
Awkward .... consider:
An expired token for an existing
ManagementAPIinstance can be replaced by calling thesetApiTokenmethod with the new token.
| } | ||
|
|
||
| /** | ||
| * Update the API token to use on new calls. This is useful when the token is about to expire or it already has. |
There was a problem hiding this comment.
"when the token is about to expire or already has"
There was a problem hiding this comment.
I had doubts on this one 😛
|
|
||
| /** | ||
| * Update the API token to use on new calls. This is useful when the token is about to expire or it already has. | ||
| * Please note you'll need to obtain the correspondent entity again for this to apply. e.g. call {@link #clients()} again. |
| * @param apiToken the token to authenticate the calls with. | ||
| */ | ||
| public void setApiToken(String apiToken) { | ||
| Asserts.assertNotNull(apiToken, "api token"); |
There was a problem hiding this comment.
I might be wrong but it looks like you've got these params backwards?
I'm not sure if Asserts.assertNotNull() is the same one.
There was a problem hiding this comment.
I think I'm wrong ... Assert is a unit testing thing, Asserts is in this lib
There was a problem hiding this comment.
Yes! Asserts is a helper class that throws an exception if a value is different than the expected. I think I mentioned this on one of my reviews to your PRs last week. It's basically to avoid boilerplate code.
if (value == null) {
throw new IllegalArgumentException(String.format("'%s' cannot be null!", name));
}BTW. At the top of the class you can see the imports and in this case, that I'm importing this lib Asserts class import com.auth0.utils.Asserts. Also in case the class is on the same package, there's no need to explicitly import it.
README.md
Outdated
| ``` | ||
|
|
||
| (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). | ||
| (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). |
|
This is fine for now, maybe think about this in next major ;) |
b440133 to
5f855e2
Compare
5f855e2 to
6bc0ae1
Compare
c51e1a9 to
b7edcb7
Compare
|
|
||
| private final HttpUrl baseUrl; | ||
| private final String apiToken; | ||
| private String apiToken; |
There was a problem hiding this comment.
I don't know if ManagementAPI is supposed to be thread safe, if yes then apiToken should have volatile modifier.
As I wrote this I thought that good alternative would be to have a function with a callback the user can implement their own logic in. So they can code a token refresher and feed that instead.
Fixes: #131