Package com.ultikits.ultitools.utils
Class DeviceAuthorizationClient
java.lang.Object
com.ultikits.ultitools.utils.DeviceAuthorizationClient
The two REST calls of the RFC 8628 device authorization grant against UltiCloud protocol v2:
POST /v1/device/authorize and POST /v1/device/token. Both routes are public; no
credential travels with them.
Neither the device code nor a granted secret ever appears in a log line, an exception or a
toString() produced here: the device code is a bearer for the grant during its lifetime.
- Since:
- 6.3.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classEither aDeviceAuthorizationClient.Grantor the operator-facing reason the request failed.(package private) static final classA device code and how to present it.(package private) static final classThe outcome of one token poll. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String(package private) static final longThe device code lifetime to assume when the response names none.(package private) static final longRFC 8628 §3.2: the poll interval to use when the response names none.(package private) static final intThe longest backend-supplied text (message, reason) this class passes on, in characters.private static final longThe longesterror.details.retryAfterSecondstaken from a 429 body.(package private) static final intThe protocol major version this framework speaks.private static final intprivate static final intprivate static final int(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) DeviceAuthorizationClient.AuthorizeResultRequests a device code.(package private) static com.google.gson.JsonObjectdataObject(String body) private static StringdescribeFailure(CloudHttp.Response response) private static longdetailsRetryAfter(String body) (package private) static com.google.gson.JsonObjecterrorObject(String body) private static booleanprivate static com.google.gson.JsonObjectparseObject(String body) (package private) DeviceAuthorizationClient.PollResultPolls for the outcome ofdeviceCodeonce.private static DeviceAuthorizationClient.PollResultMaps a 200 toGRANTED, or toTRANSIENTwith a WARNING naming what is missing.(package private) static String(package private) static Stringprivate static voidwarnUnusableGrant(String defect) Names the defect only -- never a value from the response, which may hold the secret.
-
Field Details
-
AUTHORIZE_PATH
- See Also:
-
TOKEN_PATH
- See Also:
-
PROTOCOL_VERSION
static final int PROTOCOL_VERSIONThe protocol major version this framework speaks.- See Also:
-
DEFAULT_INTERVAL_SECONDS
static final long DEFAULT_INTERVAL_SECONDSRFC 8628 §3.2: the poll interval to use when the response names none.- See Also:
-
DEFAULT_EXPIRES_IN_SECONDS
static final long DEFAULT_EXPIRES_IN_SECONDSThe device code lifetime to assume when the response names none.- See Also:
-
MAX_BACKEND_TEXT
static final int MAX_BACKEND_TEXTThe longest backend-supplied text (message, reason) this class passes on, in characters.- See Also:
-
STATUS_BAD_REQUEST
private static final int STATUS_BAD_REQUEST- See Also:
-
STATUS_TOO_MANY_REQUESTS
private static final int STATUS_TOO_MANY_REQUESTS- See Also:
-
STATUS_SERVER_ERROR
private static final int STATUS_SERVER_ERROR- See Also:
-
MAX_RETRY_AFTER_SECONDS
private static final long MAX_RETRY_AFTER_SECONDSThe longesterror.details.retryAfterSecondstaken from a 429 body.- See Also:
-
-
Constructor Details
-
DeviceAuthorizationClient
DeviceAuthorizationClient()
-
-
Method Details
-
authorize
DeviceAuthorizationClient.AuthorizeResult authorize(String frameworkVersion, String suggestedNameOrNull, String legacyServerUuidOrNull) Requests a device code.- Parameters:
frameworkVersion- the running framework version, sent verbatimsuggestedNameOrNull- the default server name for the confirmation page, ornullto omit the fieldlegacyServerUuidOrNull- this server's install id, ornullto omit the field; it is sent aslegacyServerUuidonly in the contract'scanonicalform (32 lower-case hex digits) and omitted when it has none, so a hyphenated or otherwise unusable value never reaches UltiCloud (plan 22-20, S-64)- Returns:
- the grant, or the reason it could not be obtained; never
null
-
pollToken
Polls for the outcome ofdeviceCodeonce.- Parameters:
deviceCode- the device code fromauthorize(java.lang.String, java.lang.String, java.lang.String)- Returns:
- the classified outcome; never
null
-
detailsRetryAfter
- Parameters:
body- a 429 body, ornull- Returns:
error.details.retryAfterSecondswhen it is an integer in [1, 86400], or -1
-
readGrant
Maps a 200 toGRANTED, or toTRANSIENTwith a WARNING naming what is missing. -
warnUnusableGrant
Names the defect only -- never a value from the response, which may hold the secret. -
describeFailure
- Returns:
UltiCloud answered HTTP <status>, plus the backend error code and message
-
sanitise
- Parameters:
text- backend-supplied text, ornull- Returns:
- the text with control characters replaced by spaces, trimmed and cut to
200 characters;
nullwhen nothing remains
-
dataObject
- Returns:
- the
dataobject of a{data: {...}}body, ornull
-
errorObject
- Returns:
- the
errorobject of a{error: {...}}body, ornull
-
parseObject
-
string
- Returns:
- the member as a string when it is a JSON string, otherwise
null
-
isBlank
-