001package com.nimbusds.openid.connect.provider.spi.grants;
002
003
004import net.minidev.json.JSONObject;
005
006import com.nimbusds.oauth2.sdk.ParseException;
007
008
009/**
010 * Refresh token specification.
011 */
012public class RefreshTokenSpec extends OptionalTokenSpec {
013
014
015        /**
016         * Creates a new default refresh token specification (no issue).
017         */
018        public RefreshTokenSpec() {
019
020                this(false, 0l);
021        }
022
023
024        /**
025         * Creates a new refresh token specification.
026         *
027         * @param issue    Controls the refresh token issue. If {@code true}
028         *                 a refresh token must be issued (requires a
029         *                 long-lived authorisation), {@code false} to prohibit
030         *                 issue.
031         * @param lifetime The refresh token lifetime, in seconds. Zero implies
032         *                 permanent (no expiration). Applies only if a refresh
033         *                 token is issued.
034         */
035        public RefreshTokenSpec(final boolean issue, long lifetime) {
036
037                super(issue, lifetime);
038        }
039
040
041        /**
042         * Parses a refresh token specification from the specified JSON object.
043         *
044         * @param o The JSON object. Must not be {@code null}.
045         *
046         * @return The refresh token specification.
047         *
048         * @throws ParseException If parsing failed.
049         */
050        public static RefreshTokenSpec parse(final JSONObject o)
051                throws ParseException {
052
053                OptionalTokenSpec optionalTokenSpec = OptionalTokenSpec.parse(o);
054                return new RefreshTokenSpec(optionalTokenSpec.issue(), optionalTokenSpec.getLifetime());
055        }
056}