-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for /session and /refreshTokens API's and updated relev…
…ant test cases
- Loading branch information
Showing
30 changed files
with
841 additions
and
188 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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/auth0/client/mgmt/RefreshTokensEntity.java
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,66 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.refreshtokens.RefreshToken; | ||
import com.auth0.net.BaseRequest; | ||
import com.auth0.net.Request; | ||
import com.auth0.net.VoidRequest; | ||
import com.auth0.net.client.Auth0HttpClient; | ||
import com.auth0.net.client.HttpMethod; | ||
import com.auth0.utils.Asserts; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.HttpUrl; | ||
|
||
/** | ||
* Class that provides an implementation of the Refresh Tokens methods of the Management API as defined in <a href="https://auth0.com/docs/api/management/v2#!/Refresh_Tokens">https://auth0.com/docs/api/management/v2#!/Refresh_Tokens</a> | ||
* <p> | ||
* This class is not thread-safe. | ||
* @see ManagementAPI | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public class RefreshTokensEntity extends BaseManagementEntity{ | ||
|
||
RefreshTokensEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { | ||
super(client, baseUrl, tokenProvider); | ||
} | ||
|
||
/** | ||
* Request the refresh token for a given refresh token ID. | ||
* A token with scope {@code read:refresh_tokens} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token">https://auth0.com/docs/api/management/v2/refresh-tokens/get-refresh-token</a> | ||
* @param refreshTokenId the refresh token ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<RefreshToken> get(String refreshTokenId){ | ||
Asserts.assertNotNull(refreshTokenId, "refresh token ID"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/refresh-tokens") | ||
.addPathSegment(refreshTokenId) | ||
.build() | ||
.toString(); | ||
|
||
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<RefreshToken>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the refresh token for a given refresh token ID. | ||
* * A token with scope {@code delete:refresh_tokens} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token">https://auth0.com/docs/api/management/v2/refresh-tokens/delete-refresh-token</a> | ||
* @param refreshTokenId the refresh token ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> delete(String refreshTokenId){ | ||
Asserts.assertNotNull(refreshTokenId, "refresh token ID"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/refresh-tokens") | ||
.addPathSegment(refreshTokenId) | ||
.build() | ||
.toString(); | ||
|
||
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); | ||
} | ||
} |
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,67 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.sessions.Session; | ||
import com.auth0.net.BaseRequest; | ||
import com.auth0.net.Request; | ||
import com.auth0.net.VoidRequest; | ||
import com.auth0.net.client.Auth0HttpClient; | ||
import com.auth0.net.client.HttpMethod; | ||
import com.auth0.utils.Asserts; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.HttpUrl; | ||
|
||
|
||
/** | ||
* Class that provides an implementation of the Sessions methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Sessions | ||
* <p> | ||
* This class is not thread-safe. | ||
* @see ManagementAPI | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public class SessionsEntity extends BaseManagementEntity{ | ||
|
||
SessionsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { | ||
super(client, baseUrl, tokenProvider); | ||
} | ||
|
||
/** | ||
* Request the session for a given session ID. | ||
* A token with scope {@code read:sessions} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/sessions/get-session">https://auth0.com/docs/api/management/v2/sessions/get-session</a> | ||
* @param sessionId the session ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Session> get(String sessionId){ | ||
Asserts.assertNotNull(sessionId, "session ID"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/sessions") | ||
.addPathSegment(sessionId) | ||
.build() | ||
.toString(); | ||
|
||
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Session>() { | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the session for a given session ID. | ||
* A token with scope {@code delete:sessions} is needed. | ||
* See <a href="https://auth0.com/docs/api/management/v2/sessions/delete-session">https://auth0.com/docs/api/management/v2/sessions/delete-session</a> | ||
* @param sessionId the session ID. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<Void> delete(String sessionId){ | ||
Asserts.assertNotNull(sessionId, "session ID"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/sessions") | ||
.addPathSegment(sessionId) | ||
.build() | ||
.toString(); | ||
|
||
return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); | ||
} | ||
} |
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
38 changes: 0 additions & 38 deletions
38
src/main/java/com/auth0/client/mgmt/filter/CheckpointPaginationFilter.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...json/mgmt/users/refreshtokens/Device.java → ...auth0/json/mgmt/refreshtokens/Device.java
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
2 changes: 1 addition & 1 deletion
2
...gmt/users/refreshtokens/RefreshToken.java → ...json/mgmt/refreshtokens/RefreshToken.java
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
2 changes: 1 addition & 1 deletion
2
...sers/refreshtokens/RefreshTokensPage.java → ...mgmt/refreshtokens/RefreshTokensPage.java
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
2 changes: 1 addition & 1 deletion
2
...t/users/refreshtokens/ResourceServer.java → ...on/mgmt/refreshtokens/ResourceServer.java
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
2 changes: 1 addition & 1 deletion
2
...n/mgmt/users/sessions/Authentication.java → ...h0/json/mgmt/sessions/Authentication.java
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
2 changes: 1 addition & 1 deletion
2
.../users/sessions/AuthenticationMethod.java → ...n/mgmt/sessions/AuthenticationMethod.java
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
2 changes: 1 addition & 1 deletion
2
...uth0/json/mgmt/users/sessions/Client.java → .../com/auth0/json/mgmt/sessions/Client.java
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
2 changes: 1 addition & 1 deletion
2
...uth0/json/mgmt/users/sessions/Device.java → .../com/auth0/json/mgmt/sessions/Device.java
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
2 changes: 1 addition & 1 deletion
2
...th0/json/mgmt/users/sessions/Session.java → ...com/auth0/json/mgmt/sessions/Session.java
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
2 changes: 1 addition & 1 deletion
2
...son/mgmt/users/sessions/SessionsPage.java → ...uth0/json/mgmt/sessions/SessionsPage.java
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
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
61 changes: 61 additions & 0 deletions
61
src/test/java/com/auth0/client/mgmt/RefreshTokensEntityTest.java
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,61 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.refreshtokens.RefreshToken; | ||
import com.auth0.net.Request; | ||
import com.auth0.net.client.HttpMethod; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.auth0.AssertsUtil.verifyThrows; | ||
import static com.auth0.client.MockServer.MGMT_REFRESH_TOKEN; | ||
import static com.auth0.client.RecordedRequestMatcher.hasHeader; | ||
import static com.auth0.client.RecordedRequestMatcher.hasMethodAndPath; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
public class RefreshTokensEntityTest extends BaseMgmtEntityTest{ | ||
|
||
@Test | ||
public void shouldThrowOnGetWithNullRefreshTokenId() { | ||
verifyThrows(IllegalArgumentException.class, | ||
() -> api.refreshTokens().get(null), | ||
"'refresh token ID' cannot be null!"); | ||
} | ||
|
||
@Test | ||
public void shouldGetRefreshToken() throws Exception { | ||
Request<RefreshToken> request = api.refreshTokens().get("refresh_token_ID"); | ||
assertThat(request, is(notNullValue())); | ||
|
||
server.jsonResponse(MGMT_REFRESH_TOKEN, 200); | ||
RefreshToken response =request.execute().getBody(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/refresh-tokens/refresh_token_ID")); | ||
assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); | ||
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); | ||
|
||
assertThat(response, is(notNullValue())); | ||
} | ||
|
||
@Test | ||
public void shouldThrowOnDeleteWithNullRefreshTokenId() { | ||
verifyThrows(IllegalArgumentException.class, | ||
() -> api.refreshTokens().delete(null), | ||
"'refresh token ID' cannot be null!"); | ||
} | ||
|
||
@Test | ||
public void shouldDeleteRefreshToken() throws Exception { | ||
Request<Void> request = api.refreshTokens().delete("refresh_token_ID"); | ||
assertThat(request, is(notNullValue())); | ||
|
||
server.noContentResponse(); | ||
request.execute().getBody(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/refresh-tokens/refresh_token_ID")); | ||
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); | ||
} | ||
} |
Oops, something went wrong.