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