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, -1L);
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) and negative not specified
040         *                 (to let the Connect2id server apply the default
041         *                 configured refresh token lifetime). Applies only if
042         *                 a refresh token is issued.
043         */
044        public RefreshTokenSpec(final boolean issue, long lifetime) {
045
046                super(issue, lifetime, null, null);
047        }
048
049
050        /**
051         * Parses a refresh token specification from the specified JSON object.
052         *
053         * @param o The JSON object. Must not be {@code null}.
054         *
055         * @return The refresh token specification.
056         *
057         * @throws ParseException If parsing failed.
058         */
059        public static RefreshTokenSpec parse(final JSONObject o)
060                throws ParseException {
061
062                OptionalTokenSpec optionalTokenSpec = OptionalTokenSpec.parse(o);
063                return new RefreshTokenSpec(optionalTokenSpec.issue(), optionalTokenSpec.getLifetime());
064        }
065}