diff --git a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java index 7c5741cd..459c3225 100644 --- a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java +++ b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java @@ -33,8 +33,8 @@ public PersonalAccessToken rotatePersonalAccessToken() throws GitLabApiException } /** - * Rotates the given personal access token. - * The token is revoked and a new one which will expire in one week is created to replace it. + * Rotates the personal access token used in the request header. + * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it. * Only working with GitLab 16.0 and above. * *
GitLab Endpoint: POST /personal_access_tokens/self/rotate
@@ -48,12 +48,13 @@ public PersonalAccessToken rotatePersonalAccessToken(Date expiresAt) throws GitL
}
/**
- * Rotates the given personal access token.
- * The token is revoked and a new one which will expire in one week is created to replace it.
+ * Rotates a specific personal access token.
+ * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it.
* Only working with GitLab 16.0 and above.
*
* GitLab Endpoint: POST /personal_access_tokens/:id/rotate
*
+ * @param id ID of the personal access token
* @param expiresAt Expiration date of the access token
* @return the newly created PersonalAccessToken.
* @throws GitLabApiException if any exception occurs
@@ -64,4 +65,32 @@ public PersonalAccessToken rotatePersonalAccessToken(String id, Date expiresAt)
Response response = post(Response.Status.OK, formData, "personal_access_tokens", id, "rotate");
return (response.readEntity(PersonalAccessToken.class));
}
+
+ /**
+ * Get information about the personal access token used in the request header.
+ * Only working with GitLab 16.0 and above.
+ *
+ * GitLab Endpoint: GET /personal_access_tokens/self
+ *
+ * @return the specified PersonalAccessToken.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException {
+ return getPersonalAccessToken("self");
+ }
+
+ /**
+ * Get a specific personal access token.
+ * Only working with GitLab 16.0 and above.
+ *
+ * GitLab Endpoint: GET /personal_access_tokens/:id
+ *
+ * @param id ID of the personal access token
+ * @return the specified PersonalAccessToken.
+ * @throws GitLabApiException if any exception occurs
+ */
+ public PersonalAccessToken getPersonalAccessToken(String id) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null, "personal_access_tokens", id);
+ return (response.readEntity(PersonalAccessToken.class));
+ }
}