• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/main/java/com/box/sdkgen/managers/authorization/AuthorizationManager.java
1
package com.box.sdkgen.managers.authorization;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.accesstoken.AccessToken;
15
import com.box.sdkgen.schemas.postoauth2revoke.PostOAuth2Revoke;
16
import com.box.sdkgen.schemas.postoauth2token.PostOAuth2Token;
17
import com.box.sdkgen.schemas.postoauth2tokenrefreshaccesstoken.PostOAuth2TokenRefreshAccessToken;
18
import com.box.sdkgen.serialization.json.JsonManager;
19
import java.util.Map;
20

21
public class AuthorizationManager {
22

23
  public Authentication auth;
24

25
  public NetworkSession networkSession;
26

27
  public AuthorizationManager() {
×
28
    this.networkSession = new NetworkSession();
×
29
  }
×
30

31
  protected AuthorizationManager(Builder builder) {
1✔
32
    this.auth = builder.auth;
1✔
33
    this.networkSession = builder.networkSession;
1✔
34
  }
1✔
35

36
  /**
37
   * Authorize a user by sending them through the [Box](https://box.com) website and request their
38
   * permission to act on their behalf.
39
   *
40
   * <p>This is the first step when authenticating a user using OAuth 2.0. To request a user's
41
   * authorization to use the Box APIs on their behalf you will need to send a user to the URL with
42
   * this format.
43
   *
44
   * @param queryParams Query parameters of authorizeUser method
45
   */
46
  public void authorizeUser(AuthorizeUserQueryParams queryParams) {
47
    authorizeUser(queryParams, new AuthorizeUserHeaders());
×
48
  }
×
49

50
  /**
51
   * Authorize a user by sending them through the [Box](https://box.com) website and request their
52
   * permission to act on their behalf.
53
   *
54
   * <p>This is the first step when authenticating a user using OAuth 2.0. To request a user's
55
   * authorization to use the Box APIs on their behalf you will need to send a user to the URL with
56
   * this format.
57
   *
58
   * @param queryParams Query parameters of authorizeUser method
59
   * @param headers Headers of authorizeUser method
60
   */
61
  public void authorizeUser(AuthorizeUserQueryParams queryParams, AuthorizeUserHeaders headers) {
62
    Map<String, String> queryParamsMap =
×
63
        prepareParams(
×
64
            mapOf(
×
65
                entryOf("response_type", convertToString(queryParams.getResponseType())),
×
66
                entryOf("client_id", convertToString(queryParams.getClientId())),
×
67
                entryOf("redirect_uri", convertToString(queryParams.getRedirectUri())),
×
68
                entryOf("state", convertToString(queryParams.getState())),
×
69
                entryOf("scope", convertToString(queryParams.getScope()))));
×
70
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
71
    FetchResponse response =
×
72
        this.networkSession
73
            .getNetworkClient()
×
74
            .fetch(
×
75
                new FetchOptions.Builder(
76
                        String.join(
×
77
                            "", this.networkSession.getBaseUrls().getOauth2Url(), "/authorize"),
×
78
                        "GET")
79
                    .params(queryParamsMap)
×
80
                    .headers(headersMap)
×
81
                    .responseFormat(ResponseFormat.NO_CONTENT)
×
82
                    .auth(this.auth)
×
83
                    .networkSession(this.networkSession)
×
84
                    .build());
×
85
  }
×
86

87
  /**
88
   * Request an Access Token using either a client-side obtained OAuth 2.0 authorization code or a
89
   * server-side JWT assertion.
90
   *
91
   * <p>An Access Token is a string that enables Box to verify that a request belongs to an
92
   * authorized session. In the normal order of operations you will begin by requesting
93
   * authentication from the [authorize](#get-authorize) endpoint and Box will send you an
94
   * authorization code.
95
   *
96
   * <p>You will then send this code to this endpoint to exchange it for an Access Token. The
97
   * returned Access Token can then be used to to make Box API calls.
98
   *
99
   * @param requestBody Request body of requestAccessToken method
100
   */
101
  public AccessToken requestAccessToken(PostOAuth2Token requestBody) {
102
    return requestAccessToken(requestBody, new RequestAccessTokenHeaders());
1✔
103
  }
104

105
  /**
106
   * Request an Access Token using either a client-side obtained OAuth 2.0 authorization code or a
107
   * server-side JWT assertion.
108
   *
109
   * <p>An Access Token is a string that enables Box to verify that a request belongs to an
110
   * authorized session. In the normal order of operations you will begin by requesting
111
   * authentication from the [authorize](#get-authorize) endpoint and Box will send you an
112
   * authorization code.
113
   *
114
   * <p>You will then send this code to this endpoint to exchange it for an Access Token. The
115
   * returned Access Token can then be used to to make Box API calls.
116
   *
117
   * @param requestBody Request body of requestAccessToken method
118
   * @param headers Headers of requestAccessToken method
119
   */
120
  public AccessToken requestAccessToken(
121
      PostOAuth2Token requestBody, RequestAccessTokenHeaders headers) {
122
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
123
    FetchResponse response =
1✔
124
        this.networkSession
125
            .getNetworkClient()
1✔
126
            .fetch(
1✔
127
                new FetchOptions.Builder(
128
                        String.join(
1✔
129
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/oauth2/token"),
1✔
130
                        "POST")
131
                    .headers(headersMap)
1✔
132
                    .data(JsonManager.serialize(requestBody))
1✔
133
                    .contentType("application/x-www-form-urlencoded")
1✔
134
                    .responseFormat(ResponseFormat.JSON)
1✔
135
                    .auth(this.auth)
1✔
136
                    .networkSession(this.networkSession)
1✔
137
                    .build());
1✔
138
    return JsonManager.deserialize(response.getData(), AccessToken.class);
1✔
139
  }
140

141
  /**
142
   * Refresh an Access Token using its client ID, secret, and refresh token.
143
   *
144
   * @param requestBody Request body of refreshAccessToken method
145
   */
146
  public AccessToken refreshAccessToken(PostOAuth2TokenRefreshAccessToken requestBody) {
147
    return refreshAccessToken(requestBody, new RefreshAccessTokenHeaders());
×
148
  }
149

150
  /**
151
   * Refresh an Access Token using its client ID, secret, and refresh token.
152
   *
153
   * @param requestBody Request body of refreshAccessToken method
154
   * @param headers Headers of refreshAccessToken method
155
   */
156
  public AccessToken refreshAccessToken(
157
      PostOAuth2TokenRefreshAccessToken requestBody, RefreshAccessTokenHeaders headers) {
158
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
159
    FetchResponse response =
×
160
        this.networkSession
161
            .getNetworkClient()
×
162
            .fetch(
×
163
                new FetchOptions.Builder(
164
                        String.join(
×
165
                            "",
166
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
167
                            "/oauth2/token#refresh"),
168
                        "POST")
169
                    .headers(headersMap)
×
170
                    .data(JsonManager.serialize(requestBody))
×
171
                    .contentType("application/x-www-form-urlencoded")
×
172
                    .responseFormat(ResponseFormat.JSON)
×
173
                    .auth(this.auth)
×
174
                    .networkSession(this.networkSession)
×
175
                    .build());
×
176
    return JsonManager.deserialize(response.getData(), AccessToken.class);
×
177
  }
178

179
  /**
180
   * Revoke an active Access Token, effectively logging a user out that has been previously
181
   * authenticated.
182
   *
183
   * @param requestBody Request body of revokeAccessToken method
184
   */
185
  public void revokeAccessToken(PostOAuth2Revoke requestBody) {
186
    revokeAccessToken(requestBody, new RevokeAccessTokenHeaders());
1✔
187
  }
1✔
188

189
  /**
190
   * Revoke an active Access Token, effectively logging a user out that has been previously
191
   * authenticated.
192
   *
193
   * @param requestBody Request body of revokeAccessToken method
194
   * @param headers Headers of revokeAccessToken method
195
   */
196
  public void revokeAccessToken(PostOAuth2Revoke requestBody, RevokeAccessTokenHeaders headers) {
197
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
198
    FetchResponse response =
1✔
199
        this.networkSession
200
            .getNetworkClient()
1✔
201
            .fetch(
1✔
202
                new FetchOptions.Builder(
203
                        String.join(
1✔
204
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/oauth2/revoke"),
1✔
205
                        "POST")
206
                    .headers(headersMap)
1✔
207
                    .data(JsonManager.serialize(requestBody))
1✔
208
                    .contentType("application/x-www-form-urlencoded")
1✔
209
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
210
                    .auth(this.auth)
1✔
211
                    .networkSession(this.networkSession)
1✔
212
                    .build());
1✔
213
  }
1✔
214

215
  public Authentication getAuth() {
216
    return auth;
×
217
  }
218

219
  public NetworkSession getNetworkSession() {
220
    return networkSession;
×
221
  }
222

223
  public static class Builder {
224

225
    protected Authentication auth;
226

227
    protected NetworkSession networkSession;
228

229
    public Builder() {
1✔
230
      this.networkSession = new NetworkSession();
1✔
231
    }
1✔
232

233
    public Builder auth(Authentication auth) {
234
      this.auth = auth;
1✔
235
      return this;
1✔
236
    }
237

238
    public Builder networkSession(NetworkSession networkSession) {
239
      this.networkSession = networkSession;
1✔
240
      return this;
1✔
241
    }
242

243
    public AuthorizationManager build() {
244
      return new AuthorizationManager(this);
1✔
245
    }
246
  }
247
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc