Skip to content

Commit

Permalink
Changed: users/token GET endpoint to support all available auth mecha…
Browse files Browse the repository at this point in the history
…nisms
  • Loading branch information
GPortas committed Oct 14, 2024
1 parent c44ad65 commit cce22a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/api/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,20 @@ public Response deleteToken(@Context ContainerRequestContext crc) {
@Path("token")
@AuthRequired
@GET
public Response getTokenExpirationDate() {
ApiToken token = authSvc.findApiToken(getRequestApiKey());

if (token == null) {
return notFound("Token " + getRequestApiKey() + " not found.");
public Response getTokenExpirationDate(@Context ContainerRequestContext crc) {
try {
AuthenticatedUser user = getRequestAuthenticatedUserOrDie(crc);
ApiToken token = authSvc.findApiTokenByUser(user);

if (token == null) {
return notFound("Token not found.");
}

return ok(String.format("Token %s expires on %s", token.getTokenString(), token.getExpireTime()));

} catch (WrappedResponse wr) {
return wr.getResponse();
}

return ok("Token " + getRequestApiKey() + " expires on " + token.getExpireTime());

}

@Path("token/recreate")
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ public void testAPITokenEndpoints() {
*/

createUser = UtilIT.createRandomUser();
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
createDataverseResponse.prettyPrint();
Expand All @@ -428,7 +427,7 @@ public void testAPITokenEndpoints() {
getExpiration = UtilIT.getTokenExpiration(tokenForPrivateUrlUser);
getExpiration.prettyPrint();
getExpiration.then().assertThat()
.statusCode(NOT_FOUND.getStatusCode());
.statusCode(UNAUTHORIZED.getStatusCode());

createUser = UtilIT.createRandomUser();
assertEquals(OK.getStatusCode(), createUser.getStatusCode());
Expand Down

0 comments on commit cce22a2

Please sign in to comment.