313 const DataSerializationSupport = ...;
316 const DeserializeYaml = ...;
318 const DeserializeXml = ...;
322 const AcceptList = ...;
326 const Accept = AcceptList.join(
",");
329 const AcceptMap = map {$1: True}, AcceptList;
332 const Version =
"2.2";
338 const DefaultHeaders = ...;
342 const DefaultOAuth2RedirectUrl =
"auto";
345 const DefaultOptions = ...;
359 const DataSerializationOptions = ...;
369 const EncodingSupport = ...;
373 const CompressionThreshold = 1024;
378 const OAuth2GrantOptions = ...;
382 const OAuth2AuthHeaders = ...;
386 const MinimumTokenRefresh = 1m;
389 const Oauth2TokenRefreshWindow = 10m;
392 const CustomTokenOptions = ...;
396 const PkceValueSet = ...;
451 bool oauth2_auto_refresh = True;
453 bool oauth2_token_auth_secret_only = False;
455 bool oauth2_token_use_basic_auth = False;
855 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
895 hash<auto>
get(
string path, *reference<hash<auto>> info, *hash<auto> hdr);
938 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
981 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1024 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1067 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1105 setToken(
string token_type,
string token, *
string refresh_token, *date token_expiry);
1186 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1245 hash<auto>
doSignedRequest(
string shdr, code signer,
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1250 bool needsRefresh(*hash<ExceptionInfo> ex, *hash<auto> info, *
bool body_deserialized,
auto body);
1259 bool isAuthTokenError(
int status_code, hash<auto> headers, *
bool body_deserialized, *
string body_content_type,
auto body);
1315 hash<auto>
doRequestIntern(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr, *
string assume_content_type, *
string shdr, *code signer, *
bool no_auth_retry);
1327 prepareToSend(
string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1333 hash<auto>
doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1443 hash<auto>
oauth2Auth(hash<auto> login, *reference<hash<auto>> info, *
bool refresh);
1489 nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
string ct =
'Content-Type');
1507 hash<auto>
sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *
string assume_content_type, *
string shdr, *code signer, *
bool no_auth_retry);
1513 signRequest(
string method, *
string path, *data body, reference<hash<auto>> hdr);
1670 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
2135 gotOAuth2LoginInfo(hash<auto> h);
bool requiresRefresh()
Returns True if the client requires a tokenm refresh.
string oauth2_scope_separator_char
OAuth2 scope separator char.
Definition RestClient.qm.dox.h:427
auto preprocessRequestBody(auto request_body)
Preprocesses the request body before serialization.
string oauth2_pkce
If PKCE should be used with the OAuth2 authorization_code flow; this will be the code challenge metho...
Definition RestClient.qm.dox.h:463
hash< auto > oauth2AuthIntern(hash< auto > login, *reference< hash< auto > > info, *bool refresh)
Perform OAuth2 authentication.
setAllowAnyResponse(bool val=True)
Allows the "allow any response" option to be set or cleared.
*string getToken()
Returns any token set for the connection.
string oauth2_app
OAuth2 app name.
Definition RestClient.qm.dox.h:467
string token_api_key_header
If this option is set along with a token, it indicates a header to send the token in as an API key.
Definition RestClient.qm.dox.h:449
checkOAuth2Options(hash< auto > opts, *bool no_exceptions)
Validates and sets any OAuth2 options.
string custom_token_path
REST custom refresh URI path.
Definition RestClient.qm.dox.h:489
hash< auto > patch(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP PATCH request to the REST server and returns the response
bool usingOAuth2()
Returns True if the client is configured for authentication with OAuth2.
*hash< auto > getUpdateOptionsAfterLogin(hash< auto > h, *bool refresh)
Returns options to update after an OAuth2 login.
string custom_token_method
REST custom refresh HTTP method.
Definition RestClient.qm.dox.h:487
hash< auto > getNewToken()
Get a new token from the server either with an OAuth2 token request or using the refresh token.
hash< auto > doSignedRequest(string shdr, code signer, string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr)
sends a signed HTTP request to the REST server and returns the response
static tryDecodeErrorResponse(reference< hash< auto > > h, *reference< hash< auto > > info)
tries to decode an error response
string oauth2_grant_type
OAuth2 grant type.
Definition RestClient.qm.dox.h:419
string oauth2_redirect_url
OAuth2 redirect URL.
Definition RestClient.qm.dox.h:435
signRequest(string method, *string path, *data body, reference< hash< auto > > hdr)
Signs requests before sending.
hash< auto > loginIntern(*reference< hash< auto > > info)
Authenticates with OAuth2 or a custom token method if configured.
constructor(*hash< auto > opts, *softbool do_not_connect)
calls the base class HTTPClient constructor and optionally connects to the REST server
hash< auto > doRequestIntern(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr, *string assume_content_type, *string shdr, *code signer, *bool no_auth_retry)
Makes a REST request and returns the result.
transient *code alt_token_signer
To use to sign requests to the any alt token URL.
Definition RestClient.qm.dox.h:492
string token
Any token set for the connection; will be passed as a bearer token (Authorization: Bearer ....
Definition RestClient.qm.dox.h:445
hash< auto > post(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP POST request to the REST server and returns the response
hash< auto > get(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP GET request to the REST server and returns the response
date oauth2_token_expiry
The token expiry date.
Definition RestClient.qm.dox.h:459
transient *string alt_token_signer_header
The header for the alt token signer.
Definition RestClient.qm.dox.h:494
setupUserPassword(hash< auto > opts)
Setup username and password consistently.
*LoggerInterface getLogger()
Returns the logger interface for logging.
bool allow_any_response
Return undeserializable responses as-is.
Definition RestClient.qm.dox.h:473
setContentEncoding(string enc='auto')
sets the request and desired response encoding for the object; see EncodingSupport for valid options
hash< auto > getNewTokenIntern(*reference< hash< auto > > info)
Get a new token from the server.
AbstractPollOperation startPollCustomGetToken()
Starts a custom token refresh request in a non-blocking I/O operation.
string oauth2_token_url
OAuth2 token URL.
Definition RestClient.qm.dox.h:437
nothing preparePath(reference< string > path)
sets up the path for the HTTP request URI
setupAuth(hash< auto > opts, *bool no_exceptions)
Sets up authentication info.
hash< auto > getDefaultHeaders()
returns the hash of default headers to sent in all requests
hash< auto > del(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP DELETE request to the REST server and returns the response
setOAuth2LoginInfo(hash< auto > h)
Sets options from the OAuth2 login response on the local object.
setToken(string token_type, string token, *string refresh_token, *date token_expiry)
Sets a token for authentication.
hash< auto > doValidatedRequest(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr)
The same as doRequest() except no schema validation is performed on the request.
clearAltTokenSigner()
Clears alt token signer code and the header for it.
bool isAuthTokenError(int status_code, hash< auto > headers, *bool body_deserialized, *string body_content_type, auto body)
Returns True if the response was related to an authorization token error.
string getTokenType()
Returns the token type for any token.
hash< auto > refreshTokenIntern(*reference< hash< auto > > info)
Gets a new token using the refresh token.
setLogger(*LoggerInterface logger)
Accepts a LoggerInterface object for logging (or clears it)
hash< auto > getOAuth2RefreshInfo()
Returns an OAuth2 refresh hash.
checkLogin(*reference< hash< auto > > info)
Checks if a login is necessary; if so, then the login is performed.
*hash< auto > setupCustomGetToken(reference< hash< auto > > auth_hdr)
Sets up a custom token refresh request.
string oauth2_client_id
OAuth2 client ID.
Definition RestClient.qm.dox.h:421
*hash< auto > oauth2_alt_url_subst
Alternate OAuth2 URL substitution info.
Definition RestClient.qm.dox.h:439
bool requiresOAuth2Token()
Returns True if the client requires an OAuth2 token.
string oauth2_client_secret
OAuth2 client secret.
Definition RestClient.qm.dox.h:423
bool needsRestBodyAuthErrorCheck()
Returns True if the object needs to have deserialized bodies check for authentication errors.
string token_type
The token type, if any.
Definition RestClient.qm.dox.h:443
hash< auto > put(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP PUT request to the REST server and returns the response
RestSchemaValidator::AbstractRestSchemaValidator getValidator()
returns the current validator object
int oauth2_token_expiry_hint
An expiry date hint as a value in minutes.
Definition RestClient.qm.dox.h:457
setSerialization(string data='auto')
change the serialization option for the object; see DataSerializationOptions for valid options
clearConnectionPath()
Clears the connection path when a validator is present that manages the URI path.
string oauth2_alt_token_url
Alternate OAuth2 token URL.
Definition RestClient.qm.dox.h:441
bool needsRefresh(*hash< ExceptionInfo > ex, *hash< auto > info, *bool body_deserialized, auto body)
Returns True if the request error indicates that a refresh operation should be performed.
setSendEncoding(string enc='auto')
change the data content encoding (compression) option for the object
hash< auto > get(string path, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP GET request to the REST server and returns the response
*hash< auto > oauth2_token_args
OAuth2 extra token args.
Definition RestClient.qm.dox.h:431
hash< auto > oauth2Auth(hash< auto > login, *reference< hash< auto > > info, *bool refresh)
Perform OAuth2 authentication.
static decodeError(hash< auto > h, *reference< hash< auto > > info)
decode any REST errors returned if possible
hash< auto > getOAuth2LoginInfo(string grant_type)
Returns an OAuth2 login hash.
setOAuth2Options(hash< auto > new_opts)
Sets OAuth2 options.
AbstractPollOperation startOAuth2AuthPoll(hash< auto > login)
Starts a non-blocking I/O operation to authenticate with an OAuth2 server and acquire an auth token.
AbstractPollOperation startOAuth2PollRefreshToken()
Starts an OAuth2 refresh token request in a non-blocking I/O operation.
hash< auto > processRestResponse(hash< auto > resp, string method, string path, *reference< hash< auto > > info)
Process the raw REST response received.
hash< auto > getOAuth2Options()
Return OAuth2 options.
*hash< auto > rest_body_auth_error_check
A hash to check all deserialized bodies in 200 OK server responses for authentication errors.
Definition RestClient.qm.dox.h:469
*softlist< string > oauth2_scopes
OAuth2 scope.
Definition RestClient.qm.dox.h:425
replaceDefaultHeaders(*hash< auto > hdr)
replaces default headers
setAltTokenSigner(code signer, string signer_header)
Sets alt token signer code and the header for it.
static *string getScopeString(*list< auto > scopes, string separator=' ')
Returns a scope string URI argument.
hash< auto > doRequest(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr)
sends an HTTP request to the REST server and returns the response
string password
password for authentication
Definition RestClient.qm.dox.h:416
addDefaultHeaders(hash< auto > h)
adds default headers to each request
nothing prepareMsg(string method, string path, reference< auto > body, reference< hash< auto > > hdr, string ct='Content-Type')
sets up the Content-Type header and encodes any body for sending
*hash< auto > getOAuth2AuthHeaders()
Returns headers to use with OAuth2 authorization / token requests.
AbstractPollOperation startOAuth2PollSendRecv()
Starts an OAuth2 token request in a non-blocking I/O operation.
*hash< auto > oauth2_auth_args
OAuth2 extra auth args.
Definition RestClient.qm.dox.h:429
string getSerialization()
returns the current data serialization format currently in effect for the object
hash< auto > gotOAuth2LoginInfo(hash< auto > h, *bool refresh)
Called when OAuth2 login information has been received.
*string getSendEncoding()
returns the current data content encoding (compression) object or NOTHING if no encoding option is se...
const Version
RestClient Version.
Definition RestClient.qm.dox.h:332
hash< auto > sendAndDecodeResponse(*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors, *string assume_content_type, *string shdr, *code signer, *bool no_auth_retry)
sends the outgoing HTTP message and recodes the response to data
string oauth2_auth_url
OAuth2 auth URL.
Definition RestClient.qm.dox.h:433
string refresh_token
Any refresh token granted to the client.
Definition RestClient.qm.dox.h:447
string custom_token_location
REST custom token location.
Definition RestClient.qm.dox.h:485
string username
username for authentication
Definition RestClient.qm.dox.h:414
prepareToSend(string method, reference< string > path, reference< auto > body, *reference< hash< auto > > hdr)
Prepares and processes message parameters for sending without sending the message.
date token_timestamp
Last timestamp for token acquisition.
Definition RestClient.qm.dox.h:471
string custom_token_auth
REST custom token auth method.
Definition RestClient.qm.dox.h:479
hash< auto > customGetTokenIntern(*reference< hash< auto > > info, *bool refresh)
Gets a new token using the custom token refresh method.
hash< auto > doOAuth2LoginRequest(string url, hash< auto > login, *reference< hash< auto > > info, *string real_url)
Returns the deserialized response body of an OAuth2 authorization / token request.
setValidator(RestSchemaValidator::AbstractRestSchemaValidator validator)
Sets a new REST schema validator.
bool getAllowAnyResponse()
Returns the value of the "allow any response" option.
class for REST HTTP connections; returns RestClient::RestClient objects
Definition RestClient.qm.dox.h:1610
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
authSuccess()
Flags a successful connection.
hash< auto > getExtendedInfo(*hash< auto > opts)
Returns connection info plus any extended information returned by the connection.
transient *string alt_token_signer_header
The header for the alt token signer.
Definition RestClient.qm.dox.h:1647
string getOAuth2OptionName(string opt)
Returns the OAuth2 option name for this connection.
pingImpl()
performs the internal ping
const OptionList
object connection option list
Definition RestClient.qm.dox.h:1627
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the RestConnection connection object
string getUrlOption(string opt, *bool allow_relative)
Returns the value of a URL option or throws an exception if not set.
hash< auto > real_opts
real options used when creating an object
Definition RestClient.qm.dox.h:1614
setLogger(*LoggerInterface logger)
Accepts a LoggerInterface object for logging (or clears it)
RestClient get(bool connect=True, *hash< auto > rtopts)
returns the underlying connection object
Qore::AbstractPollOperation startPollConnect(*Logger::LoggerInterface logger)
Called to start a non-blocking polling ping operation on the remote REST server.
const Options
object connection options
Definition RestClient.qm.dox.h:1624
*string getPingPath()
Returns the ping path from the ping_path option.
*hash< auto > getConnectionOptions(*hash< auto > rtopts)
Returns options for creating a new connection.
hash< auto > getOAuth2Options()
Returns OAuth2 options in a standard format.
persistInfo(RestConnection old)
Called after a new connection object is created from an existing connection.
*hash< auto > processOAuth2TokenResponseImpl(hash< auto > resp)
Processes OAuth2 login responses and returns updated options.
string getAuthorizationCodeRequest(hash< AuthCodeInfo > info=< AuthCodeInfo >{})
Returns a URI for an authorization code request.
auto getPingBody()
Returns the ping body from the ping_body option.
const OAuth2AuthRequestOptions
Options required for an OAuth2 authorization request.
Definition RestClient.qm.dox.h:1630
bool needs_auth
Connections needs authorization?
Definition RestClient.qm.dox.h:1617
RestClient setupRestClientConfig(RestClient rest)
Sets the alt token signer code and header on a RestClient object if applicable.
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
DataProvider::AbstractDataProvider getDataProvider(*hash< auto > constructor_options)
returns a data provider object for this connection
bool needsAuth()
Returns True if the connection requires OAuth2 authorization before it can be used.
checkCanConnect()
Checks if the connection can theoretically communicate, if not, sets the connection as down.
checkAuthCodeFeature()
Sets the auth code feature if supported.
string getAuthUrl(*bool allow_relative)
Returns the OAuth2 authorization URL or throws an exception if not set.
object getPollImpl()
Returns an unconnected object for a non-blocking poll operation.
static string generatePkceChallenge()
Generates a random 64-byte PKCE verifier string.
transient *code alt_token_signer
To use to sign requests to the any alt token URL.
Definition RestClient.qm.dox.h:1645
*hash< string, bool > getFeaturesImpl()
Returns a list of connection-defined features.
static hash< auto > processOptions(string name, *hash< auto > opts)
processes options for the constructor
const RCF_OAUTH2_AUTH_CODE
RestClient feature: OAuth2 Auth Code support.
Definition RestClient.qm.dox.h:1641
hash< auto > processOAuth2TokenResponse(hash< auto > resp)
Processes the OAuth2 token response.
string getUrlOptionIntern(string uri, *bool allow_relative)
Returns the value of a URL option.
setChildCapabilities()
Sets child data provider capabilities.
*hash< auto > getOAuth2AuthHeaders()
Returns headers to use with OAuth2 authorization / token requests.
RestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a RestClient object
setFeatures()
Sets features during REST client initialization.
authFailure()
Flags an authorization failure.
setupRest()
Common REST client initialization.
hash< auto > getOptions()
gets options
const OAuth2Options
All OAuth2 options.
Definition RestClient.qm.dox.h:1634
clearAltTokenSigner()
Clears alt token signer code and the header for it.
const ConnectionScheme
Connection entry info.
Definition RestClient.qm.dox.h:1620
setAltTokenSigner(code signer, string signer_header)
Sets alt token signer code and the header for it.
*LoggerInterface getLogger()
Returns the logger interface for logging.
hash< auto > getExtendedInfoAsData(*hash< auto > opts)
Returns connection info plus any extended information returned by the connection.
hash< string, bool > features
Hash of supported features.
Definition RestClient.qm.dox.h:1650
static softstring getUriValue(auto v, string separator=' ')
Returns a value for use as a URI parameter.
string getType()
returns "rest"
string getTokenUrl(*bool allow_relative)
Returns the OAuth2 token URL or throws an exception if not set.
constructor(hash< auto > config, *hash< auto > attr)
creates the RestConnection connection object
REST ping polling I/O class with OAuth2 authentication.
Definition RestClient.qm.dox.h:2033
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition RestClient.qm.dox.h:2043
*hash< SocketPollInfo > continuePoll()
Returns a hash to be used for I/O polling or NOTHING in case the poll operation is complete.
bool in_refresh
token refresh flag
Definition RestClient.qm.dox.h:2089
RestConnection conn
The REST connection.
Definition RestClient.qm.dox.h:2056
string state
Current state.
Definition RestClient.qm.dox.h:2083
string path
The URI path to use.
Definition RestClient.qm.dox.h:2074
destructor()
Destroys the object and makes any connection option updates.
string getGoal()
Returns the goal.
const SPS_OAUTH2_GET_TOKEN
OAuth2 get token state.
Definition RestClient.qm.dox.h:2040
hash< auto > real_opts
RestClient options.
Definition RestClient.qm.dox.h:2062
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition RestClient.qm.dox.h:2037
RestClient rc
The RestClient object to use for polling I/O.
Definition RestClient.qm.dox.h:2059
const SPS_COMPLETE
Complete state.
Definition RestClient.qm.dox.h:2052
bool use_path_as_is
Use path directly / ping path already prepared.
Definition RestClient.qm.dox.h:2092
*hash< auto > headers
Headers to send.
Definition RestClient.qm.dox.h:2080
const SPS_REST_PING
Execute ping request.
Definition RestClient.qm.dox.h:2049
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition RestClient.qm.dox.h:2065
*auto body
The message body to send.
Definition RestClient.qm.dox.h:2077
const SPS_CUSTOM_GET_TOKEN
Custom refresh token state.
Definition RestClient.qm.dox.h:2046
bool goal_reached
Goal reached flag.
Definition RestClient.qm.dox.h:2068
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition RestClient.qm.dox.h:2071
Mutex m()
Lock for atomicity.
constructor(RestConnection conn, RestClient rc, hash< auto > real_opts)
Creates the poller with the REST client and option hash.
the RestClient namespace contains all the objects in the RestClient module
Definition RestClient.qm.dox.h:287
Hash to use for generating authorization code requests.
Definition RestClient.qm.dox.h:291
*string code_verifier
The code verifier for PKCE (https://datatracker.ietf.org/doc/html/rfc7636)
Definition RestClient.qm.dox.h:305
*string redirect_uri
To override the redirect_uri; if not set, the oauth2_redirect_url option will be used instead.
Definition RestClient.qm.dox.h:296
*list< string > scopes
Scopes to use in the request; if not set, the oauth2_scopes option will be used instead.
Definition RestClient.qm.dox.h:299
string response_type
The response type value to use in the request.
Definition RestClient.qm.dox.h:293
*string state
The state value to use in the request.
Definition RestClient.qm.dox.h:302