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