Skip to content

Commit a9d02e8

Browse files
committed
ApplicationsApi improvements
1 parent 6e91cb3 commit a9d02e8

File tree

4 files changed

+84
-11
lines changed

4 files changed

+84
-11
lines changed

gitlab4j-api/src/main/java/org/gitlab4j/api/ApplicationsApi.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public Stream<Application> getApplicationsStream() throws GitLabApiException {
8383
* @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email)
8484
* @return the created Application instance
8585
* @throws GitLabApiException if any exception occurs
86+
* @deprecated use {@link #createApplication(String, String, List, Boolean)} instead
8687
*/
88+
@Deprecated
8789
public Application createApplication(String name, String redirectUri, ApplicationScope[] scopes)
8890
throws GitLabApiException {
8991

@@ -104,9 +106,29 @@ public Application createApplication(String name, String redirectUri, Applicatio
104106
* @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email)
105107
* @return the created Application instance
106108
* @throws GitLabApiException if any exception occurs
109+
* @deprecated use {@link #createApplication(String, String, List, Boolean)} instead
107110
*/
111+
@Deprecated
108112
public Application createApplication(String name, String redirectUri, List<ApplicationScope> scopes)
109113
throws GitLabApiException {
114+
return createApplication(name, redirectUri, scopes, null);
115+
}
116+
117+
/**
118+
* Create an OAUTH Application.
119+
*
120+
* <pre><code>GitLab Endpoint: POST /api/v4/applications</code></pre>
121+
*
122+
* @param name the name for the OAUTH Application
123+
* @param redirectUri the redirect URI for the OAUTH Application
124+
* @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email)
125+
* @param confidential The application is used where the client secret can be kept confidential. Native mobile apps and Single Page Apps are considered non-confidential
126+
* @return the created Application instance
127+
* @throws GitLabApiException if any exception occurs
128+
*/
129+
public Application createApplication(
130+
String name, String redirectUri, List<ApplicationScope> scopes, Boolean confidential)
131+
throws GitLabApiException {
110132

111133
if (scopes == null || scopes.isEmpty()) {
112134
throw new GitLabApiException("scopes cannot be null or empty");
@@ -116,7 +138,8 @@ public Application createApplication(String name, String redirectUri, List<Appli
116138
GitLabApiForm formData = new GitLabApiForm()
117139
.withParam("name", name, true)
118140
.withParam("redirect_uri", redirectUri, true)
119-
.withParam("scopes", scopesString, true);
141+
.withParam("scopes", scopesString, true)
142+
.withParam("confidential", confidential);
120143
Response response = post(Response.Status.CREATED, formData, "applications");
121144
return (response.readEntity(Application.class));
122145
}

gitlab4j-models/src/main/java/org/gitlab4j/api/models/Application.java

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Application implements Serializable {
99
private String applicationId;
1010
private String applicationName;
1111
private String callbackUrl;
12+
private Boolean confidential;
13+
private String secret;
1214

1315
public Long getId() {
1416
return id;
@@ -41,4 +43,20 @@ public String getCallbackUrl() {
4143
public void setCallbackUrl(String callbackUrl) {
4244
this.callbackUrl = callbackUrl;
4345
}
46+
47+
public Boolean getConfidential() {
48+
return confidential;
49+
}
50+
51+
public void setConfidential(Boolean confidential) {
52+
this.confidential = confidential;
53+
}
54+
55+
public String getSecret() {
56+
return secret;
57+
}
58+
59+
public void setSecret(String secret) {
60+
this.secret = secret;
61+
}
4462
}

gitlab4j-models/src/main/java/org/gitlab4j/models/Constants.java

+38-9
Original file line numberDiff line numberDiff line change
@@ -829,26 +829,55 @@ public String toString() {
829829
* Enum for the various Application scope values.
830830
*/
831831
public enum ApplicationScope {
832-
833-
/** Access the authenticated user's API */
832+
/** Grants complete read/write access to the API, including all groups and projects, the container registry, the dependency proxy, and the package registry. */
834833
API,
835834

836-
/** Read the authenticated user's personal information */
835+
/** Grants read access to the API, including all groups and projects, the container registry, and the package registry. */
836+
READ_API,
837+
838+
/** Grants read-only access to your profile through the /user API endpoint, which includes username, public email, and full name. Also grants access to read-only API endpoints under /users. */
837839
READ_USER,
838840

839-
/** Perform API actions as any user in the system */
840-
SUDO,
841+
/** Grants create access to the runners. */
842+
CREATE_RUNNER,
841843

842-
/** Allows read-access to the repository */
844+
/** Grants access to manage the runners. */
845+
MANAGE_RUNNER,
846+
847+
/** Grants permission to perform Kubernetes API calls using the agent for Kubernetes. */
848+
K8S_PROXY,
849+
850+
/** Grants read-only access to repositories on private projects using Git-over-HTTP or the Repository Files API. */
843851
READ_REPOSITORY,
844852

845-
/** Authenticate using OpenID Connect */
853+
/** Grants read-write access to repositories on private projects using Git-over-HTTP (not using the API). */
854+
WRITE_REPOSITORY,
855+
856+
/** Grants read-only access to GitLab Observability. */
857+
READ_OBSERVABILITY,
858+
859+
/** Grants write access to GitLab Observability. */
860+
WRITE_OBSERVABILITY,
861+
862+
/** Grants access to GitLab Duo related API endpoints. */
863+
AI_FEATURES,
864+
865+
/** Grants permission to perform API actions as any user in the system, when authenticated as an admin user. */
866+
SUDO,
867+
868+
/** Grants permission to perform API actions as an administrator, when Admin Mode is enabled. */
869+
ADMIN_MODE,
870+
871+
/** Grant access to download Service Ping payload via API when authenticated as an admin user. */
872+
READ_SERVICE_PING,
873+
874+
/** Grants permission to authenticate with GitLab using OpenID Connect. Also gives read-only access to the user's profile and group memberships. */
846875
OPENID,
847876

848-
/** Allows read-only access to the user's personal information using OpenID Connect */
877+
/** Grants read-only access to the user's profile data using OpenID Connect. */
849878
PROFILE,
850879

851-
/** Allows read-only access to the user's primary email address using OpenID Connect */
880+
/** Grants read-only access to the user's primary email address using OpenID Connect. */
852881
EMAIL;
853882

854883
private static JacksonJsonEnumHelper<ApplicationScope> enumHelper =

gitlab4j-models/src/test/resources/org/gitlab4j/models/applications.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"id": 1,
44
"application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737",
55
"application_name": "MyApplication",
6-
"callback_url": "http://redirect.uri"
6+
"secret": "ee1dd64b6adc89cf7e2c23099301ccc2c61b441064e9324d963c46902a85ec34"
7+
"callback_url": "http://redirect.uri",
8+
"confidential": true,
9+
"secret": "gloas-0f5cf43dab1a677cd9071743947e54468403c53056c15ba5e3724cf2b7ca17a0"
710
}
811
]

0 commit comments

Comments
 (0)