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