001package com.box.sdk;
002
003import com.eclipsesource.json.JsonArray;
004import com.eclipsesource.json.JsonObject;
005import com.eclipsesource.json.JsonValue;
006
007/** */
008public class ScopedToken extends BoxJSONObject {
009  private String accessToken;
010  private long expiresIn;
011  private String tokenType;
012  private String issuedTokenType;
013  private JsonArray restrictedTo;
014  private long obtainedAt;
015
016  /**
017   * Constructs a ScopedToken object from a parsed JsonObject.
018   *
019   * @param jsonObject parsed json object from response of token exchange
020   */
021  public ScopedToken(JsonObject jsonObject) {
022    super(jsonObject);
023  }
024
025  @Override
026  protected void parseJSONMember(JsonObject.Member member) {
027    String memberName = member.getName();
028    JsonValue value = member.getValue();
029    if (memberName.equals("access_token")) {
030      this.accessToken = value.asString();
031    } else if (memberName.equals("token_type")) {
032      this.tokenType = value.asString();
033    } else if (memberName.equals("issued_token_type")) {
034      this.issuedTokenType = value.asString();
035    } else if (memberName.equals("restricted_to")) {
036      this.restrictedTo = value.asArray();
037    }
038  }
039
040  /**
041   * Gets the lower scoped token.
042   *
043   * @return lower scoped access token
044   */
045  public String getAccessToken() {
046    return this.accessToken;
047  }
048
049  /**
050   * Gets the expires in time in milliseconds.
051   *
052   * @return the time in milliseconds after which the token expires
053   */
054  public long getExpiresIn() {
055    return this.expiresIn;
056  }
057
058  /**
059   * Sets the time in milliseconds in which this token will expire.
060   *
061   * @param milliseconds the number of milliseconds for which the access token is valid.
062   */
063  public void setExpiresIn(long milliseconds) {
064    this.expiresIn = milliseconds;
065  }
066
067  /**
068   * Gets the token type.
069   *
070   * @return the token type
071   */
072  public String getTokenType() {
073    return this.tokenType;
074  }
075
076  /**
077   * Gets the issued token type as per ietf namespace.
078   *
079   * @return the issued token type as per ietf namespace
080   */
081  public String getIssuedTokenType() {
082    return this.issuedTokenType;
083  }
084
085  /**
086   * Gets the restricted to information for the scoped token.
087   *
088   * @return the restricted to information
089   */
090  public JsonArray getRestrictedTo() {
091    return this.restrictedTo;
092  }
093
094  /**
095   * Gets the time in milliseconds when the token was obtained.
096   *
097   * @return the time in millinseconds when the token was obtained
098   */
099  public long getObtainedAt() {
100    return this.obtainedAt;
101  }
102
103  /** @param milliseconds the time in milliseconds at which it was obtained */
104  public void setObtainedAt(long milliseconds) {
105    this.obtainedAt = milliseconds;
106  }
107}