Qore RestClient Module Reference 2.3.2
Loading...
Searching...
No Matches
RestClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* RestClient.qm Copyright (C) 2013 - 2025 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum qore version
26
27// require type definitions everywhere
28
29// enable all warnings
30
31// don't use "$" for vars, members, and methods, assume local variable scope
32
33
34
35
36
37
38
39/* Version History - see below in docs
40*/
41
287namespace RestClient {
289
291public hashdecl AuthCodeInfo {
293 string response_type = "code";
294
297
299 *list<string> scopes;
300
302 *string state;
303
306};
307
310
311public:
313 const DataSerializationSupport = ...;
314
315
316 const DeserializeYaml = ...;
317
318 const DeserializeXml = ...;
319
320
322 const AcceptList = ...;
323
324
326 const Accept = AcceptList.join(",");
327
329 const AcceptMap = map {$1: True}, AcceptList;
330
332 const Version = "2.2";
333
335 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
336
338 const DefaultHeaders = ...;
339
340
342 const DefaultOAuth2RedirectUrl = "auto";
343
345 const DefaultOptions = ...;
346
347
349
359 const DataSerializationOptions = ...;
360
361
363
369 const EncodingSupport = ...;
370
371
373 const CompressionThreshold = 1024;
374
376
378 const OAuth2GrantOptions = ...;
379
380
382 const OAuth2AuthHeaders = ...;
383
384
386 const MinimumTokenRefresh = 1m;
387
389 const Oauth2TokenRefreshWindow = 10m;
390
392 const CustomTokenOptions = ...;
393
394
396 const PkceValueSet = ...;
397
398
399protected:
400 // headers to send with every request
401 hash<auto> headers;
402 // data serialization code
403 string ds;
404 // serialization content type
405 string sct;
406 // send content encoding hash
407 *hash<auto> seh;
408 // REST schema validator
410 // no_charset option
411 *bool noCharset;
412
414 string username;
416 string password;
417
425 *softlist<string> oauth2_scopes;
429 *hash<auto> oauth2_auth_args;
431 *hash<auto> oauth2_token_args;
445 string token;
451 bool oauth2_auto_refresh = True;
453 bool oauth2_token_auth_secret_only = False;
455 bool oauth2_token_use_basic_auth = False;
461
465
474
476
481
490
492 transient *code alt_token_signer;
494 transient *string alt_token_signer_header;
495
496public:
497
499
612 constructor(*hash<auto> opts, *softbool do_not_connect) ;
613
614
616 setLogger(*LoggerInterface logger);
617
618
621
622
624
628 setOAuth2Options(hash<auto> new_opts);
629
630
632
636 hash<auto> getOAuth2Options();
637
638
640
643
644
646
659 setSerialization(string data = 'auto');
660
661
663
680 setSendEncoding(string enc = 'auto');
681
682
684
701 setContentEncoding(string enc = 'auto');
702
703
705
721 addDefaultHeaders(hash<auto> h);
722
723
725
738 hash<auto> getDefaultHeaders();
739
740
742
747 replaceDefaultHeaders(*hash<auto> hdr);
748
749
751
767
768
770
783
784
786
797 setAllowAnyResponse(bool val = True);
798
799
801
810
811
813
855 hash<auto> get(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
856
857
859
895 hash<auto> get(string path, *reference<hash<auto>> info, *hash<auto> hdr);
896
897
899
938 hash<auto> put(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
939
940
942
981 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
982
983
985
1024 hash<auto> post(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1025
1026
1028
1067 hash<auto> del(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1068
1069
1071
1076
1077
1079
1082
1083
1085
1088
1089
1091
1094
1095
1097
1100
1101
1103
1105 setToken(string token_type, string token, *string refresh_token, *date token_expiry);
1106
1107
1109
1112
1113
1115
1117 *string getToken();
1118
1119
1121
1123 AbstractPollOperation startOAuth2PollSendRecv();
1124
1125
1127
1129 AbstractPollOperation startPollCustomGetToken();
1130
1131
1133
1135 AbstractPollOperation startOAuth2PollRefreshToken();
1136
1137
1139
1186 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1187
1188
1190
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);
1246
1247
1249protected:
1250 bool needsRefresh(*hash<ExceptionInfo> ex, *hash<auto> info, *bool body_deserialized, auto body);
1251public:
1252
1253
1255
1259 bool isAuthTokenError(int status_code, hash<auto> headers, *bool body_deserialized, *string body_content_type, auto body);
1260
1261
1263
1273 hash<auto> getNewToken();
1274
1275
1277
1279protected:
1280 *hash<auto> setupCustomGetToken(reference<hash<auto>> auth_hdr);
1281public:
1282
1283
1285
1288protected:
1289 hash<auto> getNewTokenIntern(*reference<hash<auto>> info);
1290public:
1291
1292
1294
1298protected:
1299 hash<auto> customGetTokenIntern(*reference<hash<auto>> info, *bool refresh);
1300public:
1301
1302
1304
1308protected:
1309 hash<auto> refreshTokenIntern(*reference<hash<auto>> info);
1310public:
1311
1312
1314protected:
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);
1316public:
1317
1318
1320
1327 prepareToSend(string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1328
1329
1331
1333 hash<auto> doValidatedRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1334
1335
1337
1344 hash<auto> processRestResponse(hash<auto> resp, string method, string path, *reference<hash<auto>> info);
1345
1346
1348
1352 hash<auto> gotOAuth2LoginInfo(hash<auto> h, *bool refresh);
1353
1354
1356
1360 auto preprocessRequestBody(auto request_body);
1361
1362
1364 *LoggerInterface getLogger();
1365
1366
1368
1373 static *string getScopeString(*list<auto> scopes, string separator = ' ');
1374
1376
1378 setAltTokenSigner(code signer, string signer_header);
1379
1380
1382
1385
1386
1388
1390protected:
1391 setOAuth2LoginInfo(hash<auto> h);
1392public:
1393
1394
1396
1398protected:
1399 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h, *bool refresh);
1400public:
1401
1402
1404
1406protected:
1407 setupAuth(hash<auto> opts, *bool no_exceptions);
1408public:
1409
1410
1412 setupUserPassword(hash<auto> opts);
1413
1414
1416
1418protected:
1419 checkOAuth2Options(hash<auto> opts, *bool no_exceptions);
1420public:
1421
1422
1424
1426protected:
1427 hash<auto> loginIntern(*reference<hash<auto>> info);
1428public:
1429
1430
1432
1434protected:
1435 AbstractPollOperation startOAuth2AuthPoll(hash<auto> login);
1436public:
1437
1438
1440
1442protected:
1443 hash<auto> oauth2Auth(hash<auto> login, *reference<hash<auto>> info, *bool refresh);
1444public:
1445
1446
1448
1450protected:
1451 hash<auto> oauth2AuthIntern(hash<auto> login, *reference<hash<auto>> info, *bool refresh);
1452public:
1453
1454
1456
1458protected:
1459 hash<auto> doOAuth2LoginRequest(string url, hash<auto> login, *reference<hash<auto>> info, *string real_url);
1460public:
1461
1462
1464
1466protected:
1468public:
1469
1470
1472
1474protected:
1475 hash<auto> getOAuth2LoginInfo(string grant_type);
1476public:
1477
1478
1480
1482protected:
1484public:
1485
1486
1488protected:
1489 nothing prepareMsg(string method, string path, reference<auto> body, reference<hash<auto>> hdr, string ct = 'Content-Type');
1490public:
1491
1492
1494protected:
1495 nothing preparePath(reference<string> path);
1496public:
1497
1498
1500protected:
1501 checkLogin(*reference<hash<auto>> info);
1502public:
1503
1504
1506protected:
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);
1508public:
1509
1510
1512protected:
1513 signRequest(string method, *string path, *data body, reference<hash<auto>> hdr);
1514public:
1515
1516
1518protected:
1519 static decodeError(hash<auto> h, *reference<hash<auto>> info);
1520public:
1521
1522
1524private:
1525 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1526public:
1527
1528}; // class RestClient
1529
1531
1611
1612public:
1614 hash<auto> real_opts;
1615
1618
1620 const ConnectionScheme = ...;
1621
1622
1624 const Options = map {$1: True}, keys ConnectionScheme.options;
1625
1627 const OptionList = keys ConnectionScheme.options;
1628
1631
1632
1634 const OAuth2Options = ...;
1635
1636
1638
1641 const RCF_OAUTH2_AUTH_CODE = "oauth2-auth-code";
1642
1643protected:
1645 transient *code alt_token_signer;
1647 transient *string alt_token_signer_header;
1648
1650 hash<string, bool> features = {
1651 CF_LOGGER: True,
1652 };
1653
1654public:
1655
1657
1670 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1671 ;
1672
1673
1675
1692 constructor(hash<auto> config, *hash<auto> attr) ;
1693
1694
1696 setLogger(*LoggerInterface logger);
1697
1698
1700 *LoggerInterface getLogger();
1701
1702
1704
1710
1711
1713
1723 hash<auto> getExtendedInfo(*hash<auto> opts);
1724
1725
1727
1736 hash<auto> getExtendedInfoAsData(*hash<auto> opts);
1737
1738
1740
1744
1745
1747
1751
1752
1754
1756 string getOAuth2OptionName(string opt);
1757
1758
1760
1764 object getPollImpl();
1765
1766
1768
1772 hash<auto> getOptions();
1773
1774
1776 string getType();
1777
1778
1780
1782 hash<auto> getOAuth2Options();
1783
1784
1786
1788 hash<auto> processOAuth2TokenResponse(hash<auto> resp);
1789
1790
1792
1795
1796
1798
1806 DataProvider::AbstractDataProvider getDataProvider(*hash<auto> constructor_options);
1807
1808
1810
1815
1816
1818
1823 Qore::AbstractPollOperation startPollConnect(*Logger::LoggerInterface logger);
1824
1825
1827
1830
1831
1833
1835 static hash<auto> processOptions(string name, *hash<auto> opts);
1836
1838
1847 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
1848
1849
1851 static string generatePkceChallenge();
1852
1854 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1855 is to return a full URL
1856
1857 @since %RestClient 2.0
1858 */
1859 string getAuthUrl(*bool allow_relative);
1860
1861
1863 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1864 is to return a full URL
1865
1866 @since %RestClient 2.0
1867 */
1868 string getTokenUrl(*bool allow_relative);
1869
1870
1872 *hash<auto> getConnectionOptions(*hash<auto> rtopts);
1873
1874
1876
1878 setAltTokenSigner(code signer, string signer_header);
1879
1880
1882
1885
1886
1888
1890 RestClient get(bool connect = True, *hash<auto> rtopts);
1891
1892
1894
1896protected:
1898public:
1899
1900
1902
1904protected:
1906public:
1907
1908
1910
1916protected:
1918public:
1919
1920
1922 /* @param opt the URL option name
1923 @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1924 is to return a full URL
1925
1926 @since %RestClient 2.1.1
1927 */
1928protected:
1929 string getUrlOption(string opt, *bool allow_relative);
1930public:
1931
1932
1934 /* @param uri the URL value
1935 @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1936 is to return a full URL
1937
1938 @since %RestClient 2.2
1939 */
1940protected:
1941 string getUrlOptionIntern(string uri, *bool allow_relative);
1942public:
1943
1944
1946 /*
1947 @since %RestClient 2.0
1948 */
1949protected:
1950 static softstring getUriValue(auto v, string separator = ' ');
1951public:
1952
1953
1955protected:
1956 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1957public:
1958
1959
1961protected:
1963public:
1964
1965
1967
1975protected:
1976 RestClient getImpl(bool connect = True, *hash<auto> rtopts);
1977public:
1978
1979
1981
1984protected:
1986public:
1987
1988
1990
1992protected:
1994public:
1995
1996
1998protected:
1999 *string getPingPath();
2000public:
2001
2002
2004protected:
2006public:
2007
2008
2010
2012protected:
2013 *hash<string, bool> getFeaturesImpl();
2014public:
2015
2016
2018protected:
2020public:
2021
2022
2024protected:
2025 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
2026public:
2027
2028};
2029
2031
2034
2035public:
2037 const SPS_GET_SWAGGER = 'get-swagger';
2038
2040 const SPS_OAUTH2_GET_TOKEN = "oauth2-get-token";
2041
2043 const SPS_OAUTH2_REFRESH_TOKEN = "oauth2-refresh-token";
2044
2046 const SPS_CUSTOM_GET_TOKEN = "custom-refresh";
2047
2049 const SPS_REST_PING = "rest-ping";
2050
2052 const SPS_COMPLETE = "complete";
2053
2054protected:
2057
2060
2062 hash<auto> real_opts;
2063
2065 AbstractPollOperation poller;
2066
2068 bool goal_reached = False;
2069
2071 string method;
2072
2074 string path;
2075
2077 *auto body;
2078
2080 *hash<auto> headers;
2081
2083 string state;
2084
2086 Mutex m();
2087
2090
2093
2094public:
2095
2098
2099
2102
2103
2105
2107 string getGoal();
2108
2109
2111
2113 string getState();
2114
2115
2117
2120
2121
2123 *hash<SocketPollInfo> continuePoll();
2124
2125
2126 abort();
2127
2128
2129protected:
2130 checkOtherStates();
2131public:
2132
2133
2134protected:
2135 gotOAuth2LoginInfo(hash<auto> h);
2136public:
2137
2138
2139protected:
2140 doStartGetToken();
2141public:
2142
2143
2144protected:
2145 doStartRefresh();
2146public:
2147
2148
2149protected:
2150 doStartPing();
2151public:
2152
2153
2154protected:
2155 checkUrl();
2156public:
2157
2158};
2159};
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