001package com.box.sdkgen.schemas.postoauth2token;
002
003import com.box.sdkgen.internal.NullableFieldTracker;
004import com.box.sdkgen.internal.SerializableObject;
005import com.box.sdkgen.serialization.json.EnumWrapper;
006import com.fasterxml.jackson.annotation.JsonFilter;
007import com.fasterxml.jackson.annotation.JsonProperty;
008import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
009import com.fasterxml.jackson.databind.annotation.JsonSerialize;
010import java.util.Objects;
011
012/** A request for a new OAuth 2.0 token. */
013@JsonFilter("nullablePropertyFilter")
014public class PostOAuth2Token extends SerializableObject {
015
016  /**
017   * The type of request being made, either using a client-side obtained authorization code, a
018   * refresh token, a JWT assertion, client credentials grant or another access token for the
019   * purpose of downscoping a token.
020   */
021  @JsonDeserialize(
022      using = PostOAuth2TokenGrantTypeField.PostOAuth2TokenGrantTypeFieldDeserializer.class)
023  @JsonSerialize(
024      using = PostOAuth2TokenGrantTypeField.PostOAuth2TokenGrantTypeFieldSerializer.class)
025  @JsonProperty("grant_type")
026  protected final EnumWrapper<PostOAuth2TokenGrantTypeField> grantType;
027
028  /**
029   * The Client ID of the application requesting an access token.
030   *
031   * <p>Used in combination with `authorization_code`, `client_credentials`, or
032   * `urn:ietf:params:oauth:grant-type:jwt-bearer` as the `grant_type`.
033   */
034  @JsonProperty("client_id")
035  protected String clientId;
036
037  /**
038   * The client secret of the application requesting an access token.
039   *
040   * <p>Used in combination with `authorization_code`, `client_credentials`, or
041   * `urn:ietf:params:oauth:grant-type:jwt-bearer` as the `grant_type`.
042   */
043  @JsonProperty("client_secret")
044  protected String clientSecret;
045
046  /**
047   * The client-side authorization code passed to your application by Box in the browser redirect
048   * after the user has successfully granted your application permission to make API calls on their
049   * behalf.
050   *
051   * <p>Used in combination with `authorization_code` as the `grant_type`.
052   */
053  protected String code;
054
055  /**
056   * A refresh token used to get a new access token with.
057   *
058   * <p>Used in combination with `refresh_token` as the `grant_type`.
059   */
060  @JsonProperty("refresh_token")
061  protected String refreshToken;
062
063  /**
064   * A JWT assertion for which to request a new access token.
065   *
066   * <p>Used in combination with `urn:ietf:params:oauth:grant-type:jwt-bearer` as the `grant_type`.
067   */
068  protected String assertion;
069
070  /**
071   * The token to exchange for a downscoped token. This can be a regular access token, a JWT
072   * assertion, or an app token.
073   *
074   * <p>Used in combination with `urn:ietf:params:oauth:grant-type:token-exchange` as the
075   * `grant_type`.
076   */
077  @JsonProperty("subject_token")
078  protected String subjectToken;
079
080  /**
081   * The type of `subject_token` passed in.
082   *
083   * <p>Used in combination with `urn:ietf:params:oauth:grant-type:token-exchange` as the
084   * `grant_type`.
085   */
086  @JsonDeserialize(
087      using =
088          PostOAuth2TokenSubjectTokenTypeField.PostOAuth2TokenSubjectTokenTypeFieldDeserializer
089              .class)
090  @JsonSerialize(
091      using =
092          PostOAuth2TokenSubjectTokenTypeField.PostOAuth2TokenSubjectTokenTypeFieldSerializer.class)
093  @JsonProperty("subject_token_type")
094  protected EnumWrapper<PostOAuth2TokenSubjectTokenTypeField> subjectTokenType;
095
096  /**
097   * The token used to create an annotator token. This is a JWT assertion.
098   *
099   * <p>Used in combination with `urn:ietf:params:oauth:grant-type:token-exchange` as the
100   * `grant_type`.
101   */
102  @JsonProperty("actor_token")
103  protected String actorToken;
104
105  /**
106   * The type of `actor_token` passed in.
107   *
108   * <p>Used in combination with `urn:ietf:params:oauth:grant-type:token-exchange` as the
109   * `grant_type`.
110   */
111  @JsonDeserialize(
112      using =
113          PostOAuth2TokenActorTokenTypeField.PostOAuth2TokenActorTokenTypeFieldDeserializer.class)
114  @JsonSerialize(
115      using = PostOAuth2TokenActorTokenTypeField.PostOAuth2TokenActorTokenTypeFieldSerializer.class)
116  @JsonProperty("actor_token_type")
117  protected EnumWrapper<PostOAuth2TokenActorTokenTypeField> actorTokenType;
118
119  /**
120   * The space-delimited list of scopes that you want apply to the new access token.
121   *
122   * <p>The `subject_token` will need to have all of these scopes or the call will error with **401
123   * Unauthorized**..
124   */
125  protected String scope;
126
127  /** Full URL for the file that the token should be generated for. */
128  protected String resource;
129
130  /** Used in combination with `client_credentials` as the `grant_type`. */
131  @JsonDeserialize(
132      using =
133          PostOAuth2TokenBoxSubjectTypeField.PostOAuth2TokenBoxSubjectTypeFieldDeserializer.class)
134  @JsonSerialize(
135      using = PostOAuth2TokenBoxSubjectTypeField.PostOAuth2TokenBoxSubjectTypeFieldSerializer.class)
136  @JsonProperty("box_subject_type")
137  protected EnumWrapper<PostOAuth2TokenBoxSubjectTypeField> boxSubjectType;
138
139  /**
140   * Used in combination with `client_credentials` as the `grant_type`. Value is determined by
141   * `box_subject_type`. If `user` use user ID and if `enterprise` use enterprise ID.
142   */
143  @JsonProperty("box_subject_id")
144  protected String boxSubjectId;
145
146  /** Full URL of the shared link on the file or folder that the token should be generated for. */
147  @JsonProperty("box_shared_link")
148  protected String boxSharedLink;
149
150  public PostOAuth2Token(PostOAuth2TokenGrantTypeField grantType) {
151    super();
152    this.grantType = new EnumWrapper<PostOAuth2TokenGrantTypeField>(grantType);
153  }
154
155  public PostOAuth2Token(
156      @JsonProperty("grant_type") EnumWrapper<PostOAuth2TokenGrantTypeField> grantType) {
157    super();
158    this.grantType = grantType;
159  }
160
161  protected PostOAuth2Token(Builder builder) {
162    super();
163    this.grantType = builder.grantType;
164    this.clientId = builder.clientId;
165    this.clientSecret = builder.clientSecret;
166    this.code = builder.code;
167    this.refreshToken = builder.refreshToken;
168    this.assertion = builder.assertion;
169    this.subjectToken = builder.subjectToken;
170    this.subjectTokenType = builder.subjectTokenType;
171    this.actorToken = builder.actorToken;
172    this.actorTokenType = builder.actorTokenType;
173    this.scope = builder.scope;
174    this.resource = builder.resource;
175    this.boxSubjectType = builder.boxSubjectType;
176    this.boxSubjectId = builder.boxSubjectId;
177    this.boxSharedLink = builder.boxSharedLink;
178    markNullableFieldsAsSet(builder.getExplicitlySetNullableFields());
179  }
180
181  public EnumWrapper<PostOAuth2TokenGrantTypeField> getGrantType() {
182    return grantType;
183  }
184
185  public String getClientId() {
186    return clientId;
187  }
188
189  public String getClientSecret() {
190    return clientSecret;
191  }
192
193  public String getCode() {
194    return code;
195  }
196
197  public String getRefreshToken() {
198    return refreshToken;
199  }
200
201  public String getAssertion() {
202    return assertion;
203  }
204
205  public String getSubjectToken() {
206    return subjectToken;
207  }
208
209  public EnumWrapper<PostOAuth2TokenSubjectTokenTypeField> getSubjectTokenType() {
210    return subjectTokenType;
211  }
212
213  public String getActorToken() {
214    return actorToken;
215  }
216
217  public EnumWrapper<PostOAuth2TokenActorTokenTypeField> getActorTokenType() {
218    return actorTokenType;
219  }
220
221  public String getScope() {
222    return scope;
223  }
224
225  public String getResource() {
226    return resource;
227  }
228
229  public EnumWrapper<PostOAuth2TokenBoxSubjectTypeField> getBoxSubjectType() {
230    return boxSubjectType;
231  }
232
233  public String getBoxSubjectId() {
234    return boxSubjectId;
235  }
236
237  public String getBoxSharedLink() {
238    return boxSharedLink;
239  }
240
241  @Override
242  public boolean equals(Object o) {
243    if (this == o) {
244      return true;
245    }
246    if (o == null || getClass() != o.getClass()) {
247      return false;
248    }
249    PostOAuth2Token casted = (PostOAuth2Token) o;
250    return Objects.equals(grantType, casted.grantType)
251        && Objects.equals(clientId, casted.clientId)
252        && Objects.equals(clientSecret, casted.clientSecret)
253        && Objects.equals(code, casted.code)
254        && Objects.equals(refreshToken, casted.refreshToken)
255        && Objects.equals(assertion, casted.assertion)
256        && Objects.equals(subjectToken, casted.subjectToken)
257        && Objects.equals(subjectTokenType, casted.subjectTokenType)
258        && Objects.equals(actorToken, casted.actorToken)
259        && Objects.equals(actorTokenType, casted.actorTokenType)
260        && Objects.equals(scope, casted.scope)
261        && Objects.equals(resource, casted.resource)
262        && Objects.equals(boxSubjectType, casted.boxSubjectType)
263        && Objects.equals(boxSubjectId, casted.boxSubjectId)
264        && Objects.equals(boxSharedLink, casted.boxSharedLink);
265  }
266
267  @Override
268  public int hashCode() {
269    return Objects.hash(
270        grantType,
271        clientId,
272        clientSecret,
273        code,
274        refreshToken,
275        assertion,
276        subjectToken,
277        subjectTokenType,
278        actorToken,
279        actorTokenType,
280        scope,
281        resource,
282        boxSubjectType,
283        boxSubjectId,
284        boxSharedLink);
285  }
286
287  @Override
288  public String toString() {
289    return "PostOAuth2Token{"
290        + "grantType='"
291        + grantType
292        + '\''
293        + ", "
294        + "clientId='"
295        + clientId
296        + '\''
297        + ", "
298        + "clientSecret='"
299        + clientSecret
300        + '\''
301        + ", "
302        + "code='"
303        + code
304        + '\''
305        + ", "
306        + "refreshToken='"
307        + refreshToken
308        + '\''
309        + ", "
310        + "assertion='"
311        + assertion
312        + '\''
313        + ", "
314        + "subjectToken='"
315        + subjectToken
316        + '\''
317        + ", "
318        + "subjectTokenType='"
319        + subjectTokenType
320        + '\''
321        + ", "
322        + "actorToken='"
323        + actorToken
324        + '\''
325        + ", "
326        + "actorTokenType='"
327        + actorTokenType
328        + '\''
329        + ", "
330        + "scope='"
331        + scope
332        + '\''
333        + ", "
334        + "resource='"
335        + resource
336        + '\''
337        + ", "
338        + "boxSubjectType='"
339        + boxSubjectType
340        + '\''
341        + ", "
342        + "boxSubjectId='"
343        + boxSubjectId
344        + '\''
345        + ", "
346        + "boxSharedLink='"
347        + boxSharedLink
348        + '\''
349        + "}";
350  }
351
352  public static class Builder extends NullableFieldTracker {
353
354    protected final EnumWrapper<PostOAuth2TokenGrantTypeField> grantType;
355
356    protected String clientId;
357
358    protected String clientSecret;
359
360    protected String code;
361
362    protected String refreshToken;
363
364    protected String assertion;
365
366    protected String subjectToken;
367
368    protected EnumWrapper<PostOAuth2TokenSubjectTokenTypeField> subjectTokenType;
369
370    protected String actorToken;
371
372    protected EnumWrapper<PostOAuth2TokenActorTokenTypeField> actorTokenType;
373
374    protected String scope;
375
376    protected String resource;
377
378    protected EnumWrapper<PostOAuth2TokenBoxSubjectTypeField> boxSubjectType;
379
380    protected String boxSubjectId;
381
382    protected String boxSharedLink;
383
384    public Builder(PostOAuth2TokenGrantTypeField grantType) {
385      super();
386      this.grantType = new EnumWrapper<PostOAuth2TokenGrantTypeField>(grantType);
387    }
388
389    public Builder(EnumWrapper<PostOAuth2TokenGrantTypeField> grantType) {
390      super();
391      this.grantType = grantType;
392    }
393
394    public Builder clientId(String clientId) {
395      this.clientId = clientId;
396      return this;
397    }
398
399    public Builder clientSecret(String clientSecret) {
400      this.clientSecret = clientSecret;
401      return this;
402    }
403
404    public Builder code(String code) {
405      this.code = code;
406      return this;
407    }
408
409    public Builder refreshToken(String refreshToken) {
410      this.refreshToken = refreshToken;
411      return this;
412    }
413
414    public Builder assertion(String assertion) {
415      this.assertion = assertion;
416      return this;
417    }
418
419    public Builder subjectToken(String subjectToken) {
420      this.subjectToken = subjectToken;
421      return this;
422    }
423
424    public Builder subjectTokenType(PostOAuth2TokenSubjectTokenTypeField subjectTokenType) {
425      this.subjectTokenType =
426          new EnumWrapper<PostOAuth2TokenSubjectTokenTypeField>(subjectTokenType);
427      return this;
428    }
429
430    public Builder subjectTokenType(
431        EnumWrapper<PostOAuth2TokenSubjectTokenTypeField> subjectTokenType) {
432      this.subjectTokenType = subjectTokenType;
433      return this;
434    }
435
436    public Builder actorToken(String actorToken) {
437      this.actorToken = actorToken;
438      return this;
439    }
440
441    public Builder actorTokenType(PostOAuth2TokenActorTokenTypeField actorTokenType) {
442      this.actorTokenType = new EnumWrapper<PostOAuth2TokenActorTokenTypeField>(actorTokenType);
443      return this;
444    }
445
446    public Builder actorTokenType(EnumWrapper<PostOAuth2TokenActorTokenTypeField> actorTokenType) {
447      this.actorTokenType = actorTokenType;
448      return this;
449    }
450
451    public Builder scope(String scope) {
452      this.scope = scope;
453      return this;
454    }
455
456    public Builder resource(String resource) {
457      this.resource = resource;
458      return this;
459    }
460
461    public Builder boxSubjectType(PostOAuth2TokenBoxSubjectTypeField boxSubjectType) {
462      this.boxSubjectType = new EnumWrapper<PostOAuth2TokenBoxSubjectTypeField>(boxSubjectType);
463      return this;
464    }
465
466    public Builder boxSubjectType(EnumWrapper<PostOAuth2TokenBoxSubjectTypeField> boxSubjectType) {
467      this.boxSubjectType = boxSubjectType;
468      return this;
469    }
470
471    public Builder boxSubjectId(String boxSubjectId) {
472      this.boxSubjectId = boxSubjectId;
473      return this;
474    }
475
476    public Builder boxSharedLink(String boxSharedLink) {
477      this.boxSharedLink = boxSharedLink;
478      return this;
479    }
480
481    public PostOAuth2Token build() {
482      return new PostOAuth2Token(this);
483    }
484  }
485}