-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to update the Management API token #141
Conversation
README.md
Outdated
@@ -268,6 +268,9 @@ ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", holder.getAccessToken()) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awkward .... consider:
An expired token for an existing
ManagementAPI
instance can be replaced by calling thesetApiToken
method with the new token.
@@ -45,6 +46,18 @@ public ManagementAPI(String domain, String apiToken) { | |||
.build(); | |||
} | |||
|
|||
/** | |||
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"when the token is about to expire or already has"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had doubts on this one 😛
@@ -45,6 +46,18 @@ public ManagementAPI(String domain, String apiToken) { | |||
.build(); | |||
} | |||
|
|||
/** | |||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"corresponding"
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong but it looks like you've got these params backwards?
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertNotNull(java.lang.Object)
I'm not sure if Asserts.assertNotNull()
is the same one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm wrong ... Assert
is a unit testing thing, Asserts
is in this lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -264,10 +264,13 @@ TokenHolder holder = authRequest.execute(); | |||
ManagementAPI mgmt = new ManagementAPI("{YOUR_DOMAIN}", holder.getAccessToken()); | |||
``` | |||
|
|||
(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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the simplified
sounds weird.
This is fine for now, maybe think about this in next major ;) |
b440133
to
5f855e2
Compare
5f855e2
to
6bc0ae1
Compare
c51e1a9
to
b7edcb7
Compare
@@ -15,16 +15,17 @@ | |||
public class ManagementAPI { | |||
|
|||
private final HttpUrl baseUrl; | |||
private final String apiToken; | |||
private String apiToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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