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 - 2024 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
280namespace RestClient {
282
284public hashdecl AuthCodeInfo {
286 string response_type = "code";
287
290
292 *list<string> scopes;
293
295 *string state;
296};
297
300
301public:
303 const DataSerializationSupport = ...;
304
305
306 const DeserializeYaml = ...;
307
308 const DeserializeXml = ...;
309
310
312 const AcceptList = ...;
313
314
316 const Accept = AcceptList.join(",");
317
319 const AcceptMap = map {$1: True}, AcceptList;
320
322 const Version = "2.2";
323
325 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
326
328 const DefaultHeaders = ...;
329
330
332 const DefaultOAuth2RedirectUrl = "auto";
333
335 const DefaultOptions = ...;
336
337
339
349 const DataSerializationOptions = ...;
350
351
353
359 const EncodingSupport = ...;
360
361
363 const CompressionThreshold = 1024;
364
366
368 const OAuth2GrantOptions = ...;
369
370
372 const OAuth2AuthHeaders = ...;
373
374
376 const MinimumTokenRefresh = 1m;
377
379 const Oauth2TokenRefreshWindow = 10m;
380
382 const CustomTokenOptions = ...;
383
384
385protected:
386 // headers to send with every request
387 hash<auto> headers;
388 // data serialization code
389 string ds;
390 // serialization content type
391 string sct;
392 // send content encoding hash
393 *hash<auto> seh;
394 // REST schema validator
396 // no_charset option
397 *bool noCharset;
398
400 string username;
402 string password;
403
411 *softlist<string> oauth2_scopes;
415 *hash<auto> oauth2_auth_args;
417 *hash<auto> oauth2_token_args;
431 string token;
437 bool oauth2_auto_refresh = True;
439 bool oauth2_token_auth_secret_only = False;
441 bool oauth2_token_use_basic_auth = False;
447
449 bool oauth2_pkce = False;
451
458
460
465
474
476 transient *code alt_token_signer;
478 transient *string alt_token_signer_header;
479
480public:
481
483
596 constructor(*hash<auto> opts, *softbool do_not_connect) ;
597
598
600 setLogger(*LoggerInterface logger);
601
602
605
606
608
612 setOAuth2Options(hash<auto> new_opts);
613
614
616
620 hash<auto> getOAuth2Options();
621
622
624
627
628
630
643 setSerialization(string data = 'auto');
644
645
647
664 setSendEncoding(string enc = 'auto');
665
666
668
685 setContentEncoding(string enc = 'auto');
686
687
689
705 addDefaultHeaders(hash<auto> h);
706
707
709
722 hash<auto> getDefaultHeaders();
723
724
726
731 replaceDefaultHeaders(*hash<auto> hdr);
732
733
735
751
752
754
767
768
770
812 hash<auto> get(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
813
814
816
852 hash<auto> get(string path, *reference<hash<auto>> info, *hash<auto> hdr);
853
854
856
895 hash<auto> put(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
896
897
899
938 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
939
940
942
981 hash<auto> post(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
982
983
985
1024 hash<auto> del(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1025
1026
1028
1033
1034
1036
1039
1040
1042
1045
1046
1048
1051
1052
1054
1057
1058
1060
1062 setToken(string token_type, string token, *string refresh_token, *date token_expiry);
1063
1064
1066
1069
1070
1072
1074 *string getToken();
1075
1076
1078
1080 AbstractPollOperation startOAuth2PollSendRecv();
1081
1082
1084
1086 AbstractPollOperation startPollCustomGetToken();
1087
1088
1090
1092 AbstractPollOperation startOAuth2PollRefreshToken();
1093
1094
1096
1143 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1144
1145
1147
1200 hash<auto> doSignedRequest(string shdr, code signer, string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1201
1202
1204protected:
1205 bool needsRefresh(*hash<ExceptionInfo> ex, *hash<auto> info, *bool body_deserialized, auto body);
1206public:
1207
1208
1210
1214 bool isAuthTokenError(int status_code, hash<auto> headers, *bool body_deserialized, *string body_content_type, auto body);
1215
1216
1218
1228 hash<auto> getNewToken();
1229
1230
1232
1234protected:
1235 *hash<auto> setupCustomGetToken(reference<hash<auto>> auth_hdr);
1236public:
1237
1238
1240
1243protected:
1244 hash<auto> getNewTokenIntern(*reference<hash<auto>> info);
1245public:
1246
1247
1249
1253protected:
1254 hash<auto> customGetTokenIntern(*reference<hash<auto>> info, *bool refresh);
1255public:
1256
1257
1259
1263protected:
1264 hash<auto> refreshTokenIntern(*reference<hash<auto>> info);
1265public:
1266
1267
1269protected:
1270 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);
1271public:
1272
1273
1275
1282 prepareToSend(string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1283
1284
1286
1288 hash<auto> doValidatedRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1289
1290
1292
1299 hash<auto> processRestResponse(hash<auto> resp, string method, string path, *reference<hash<auto>> info);
1300
1301
1303
1307 hash<auto> gotOAuth2LoginInfo(hash<auto> h, *bool refresh);
1308
1309
1311
1315 auto preprocessRequestBody(auto request_body);
1316
1317
1319 *LoggerInterface getLogger();
1320
1321
1323
1328 static *string getScopeString(*list<auto> scopes, string separator = ' ');
1329
1331
1333 setAltTokenSigner(code signer, string signer_header);
1334
1335
1337
1340
1341
1343
1345protected:
1346 setOAuth2LoginInfo(hash<auto> h);
1347public:
1348
1349
1351
1353protected:
1354 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h, *bool refresh);
1355public:
1356
1357
1359
1361protected:
1362 setupAuth(hash<auto> opts, *bool no_exceptions);
1363public:
1364
1365
1367 setupUserPassword(hash<auto> opts);
1368
1369
1371
1373protected:
1374 checkOAuth2Options(hash<auto> opts, *bool no_exceptions);
1375public:
1376
1377
1379
1381protected:
1382 hash<auto> loginIntern(*reference<hash<auto>> info);
1383public:
1384
1385
1387
1389protected:
1390 AbstractPollOperation startOAuth2AuthPoll(hash<auto> login);
1391public:
1392
1393
1395
1397protected:
1398 hash<auto> oauth2Auth(hash<auto> login, *reference<hash<auto>> info, *bool refresh);
1399public:
1400
1401
1403
1405protected:
1406 hash<auto> oauth2AuthIntern(hash<auto> login, *reference<hash<auto>> info, *bool refresh);
1407public:
1408
1409
1411
1413protected:
1414 hash<auto> doOAuth2LoginRequest(string url, hash<auto> login, *reference<hash<auto>> info, *string real_url);
1415public:
1416
1417
1419
1421protected:
1423public:
1424
1425
1427
1429protected:
1430 hash<auto> getOAuth2LoginInfo(string grant_type);
1431public:
1432
1433
1435
1437protected:
1439public:
1440
1441
1443protected:
1444 nothing prepareMsg(string method, string path, reference<auto> body, reference<hash<auto>> hdr, string ct = 'Content-Type');
1445public:
1446
1447
1449protected:
1450 nothing preparePath(reference<string> path);
1451public:
1452
1453
1455protected:
1456 checkLogin(*reference<hash<auto>> info);
1457public:
1458
1459
1461protected:
1462 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);
1463public:
1464
1465
1467protected:
1468 static decodeError(hash<auto> h, *reference<hash<auto>> info);
1469public:
1470
1471
1473private:
1474 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1475public:
1476
1477}; // class RestClient
1478
1480
1560
1561public:
1563 hash<auto> real_opts;
1564
1567
1569 const ConnectionScheme = ...;
1570
1571
1573 const Options = map {$1: True}, keys ConnectionScheme.options;
1574
1576 const OptionList = keys ConnectionScheme.options;
1577
1580
1581
1583 const OAuth2Options = ...;
1584
1585
1587
1590 const RCF_OAUTH2_AUTH_CODE = "oauth2-auth-code";
1591
1592protected:
1594 transient *code alt_token_signer;
1596 transient *string alt_token_signer_header;
1597
1599 hash<string, bool> features = {
1600 CF_LOGGER: True,
1601 };
1602
1603public:
1604
1606
1619 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1620 ;
1621
1622
1624
1641 constructor(hash<auto> config, *hash<auto> attr) ;
1642
1643
1645 setLogger(*LoggerInterface logger);
1646
1647
1649 *LoggerInterface getLogger();
1650
1651
1653
1659
1660
1662
1672 hash<auto> getExtendedInfo(*hash<auto> opts);
1673
1674
1676
1685 hash<auto> getExtendedInfoAsData(*hash<auto> opts);
1686
1687
1689
1693
1694
1696
1700
1701
1703
1705 string getOAuth2OptionName(string opt);
1706
1707
1709
1713 object getPollImpl();
1714
1715
1717
1721 hash<auto> getOptions();
1722
1723
1725 string getType();
1726
1727
1729
1731 hash<auto> getOAuth2Options();
1732
1733
1735
1737 hash<auto> processOAuth2TokenResponse(hash<auto> resp);
1738
1739
1741
1744
1745
1747
1755 DataProvider::AbstractDataProvider getDataProvider(*hash<auto> constructor_options);
1756
1757
1759
1764
1765
1767
1772 Qore::AbstractPollOperation startPollConnect(*Logger::LoggerInterface logger);
1773
1774
1776
1779
1780
1782
1784 static hash<auto> processOptions(string name, *hash<auto> opts);
1785
1787
1794 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
1795
1796
1798 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1799 is to return a full URL
1800
1801 @since %RestClient 2.0
1802 */
1803 string getAuthUrl(*bool allow_relative);
1804
1805
1807 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1808 is to return a full URL
1809
1810 @since %RestClient 2.0
1811 */
1812 string getTokenUrl(*bool allow_relative);
1813
1814
1816 *hash<auto> getConnectionOptions(*hash<auto> rtopts);
1817
1818
1820
1822 setAltTokenSigner(code signer, string signer_header);
1823
1824
1826
1829
1830
1832
1834 RestClient get(bool connect = True, *hash<auto> rtopts);
1835
1836
1838
1840protected:
1842public:
1843
1844
1846
1848protected:
1850public:
1851
1852
1854
1860protected:
1862public:
1863
1864
1866 /* @param opt the URL option name
1867 @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1868 is to return a full URL
1869
1870 @since %RestClient 2.1.1
1871 */
1872protected:
1873 string getUrlOption(string opt, *bool allow_relative);
1874public:
1875
1876
1878 /* @param uri the URL value
1879 @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1880 is to return a full URL
1881
1882 @since %RestClient 2.2
1883 */
1884protected:
1885 string getUrlOptionIntern(string uri, *bool allow_relative);
1886public:
1887
1888
1890 /*
1891 @since %RestClient 2.0
1892 */
1893protected:
1894 static softstring getUriValue(auto v, string separator = ' ');
1895public:
1896
1897
1899protected:
1900 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1901public:
1902
1903
1905protected:
1907public:
1908
1909
1911
1919protected:
1920 RestClient getImpl(bool connect = True, *hash<auto> rtopts);
1921public:
1922
1923
1925
1928protected:
1930public:
1931
1932
1934
1936protected:
1938public:
1939
1940
1942protected:
1943 *string getPingPath();
1944public:
1945
1946
1948protected:
1950public:
1951
1952
1954
1956protected:
1957 *hash<string, bool> getFeaturesImpl();
1958public:
1959
1960
1962protected:
1964public:
1965
1966
1968protected:
1969 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
1970public:
1971
1972};
1973
1975
1978
1979public:
1981 const SPS_GET_SWAGGER = 'get-swagger';
1982
1984 const SPS_OAUTH2_GET_TOKEN = "oauth2-get-token";
1985
1987 const SPS_OAUTH2_REFRESH_TOKEN = "oauth2-refresh-token";
1988
1990 const SPS_CUSTOM_GET_TOKEN = "custom-refresh";
1991
1993 const SPS_REST_PING = "rest-ping";
1994
1996 const SPS_COMPLETE = "complete";
1997
1998protected:
2001
2004
2006 hash<auto> real_opts;
2007
2009 AbstractPollOperation poller;
2010
2012 bool goal_reached = False;
2013
2015 string method;
2016
2018 string path;
2019
2021 *auto body;
2022
2024 *hash<auto> headers;
2025
2027 string state;
2028
2030 Mutex m();
2031
2034
2037
2038public:
2039
2042
2043
2046
2047
2049
2051 string getGoal();
2052
2053
2055
2057 string getState();
2058
2059
2061
2064
2065
2067 *hash<SocketPollInfo> continuePoll();
2068
2069
2070 abort();
2071
2072
2073protected:
2074 checkOtherStates();
2075public:
2076
2077
2078protected:
2079 gotOAuth2LoginInfo(hash<auto> h);
2080public:
2081
2082
2083protected:
2084 doStartGetToken();
2085public:
2086
2087
2088protected:
2089 doStartRefresh();
2090public:
2091
2092
2093protected:
2094 doStartPing();
2095public:
2096
2097
2098protected:
2099 checkUrl();
2100public:
2101
2102};
2103};
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:413
auto preprocessRequestBody(auto request_body)
Preprocesses the request body before serialization.
hash< auto > oauth2AuthIntern(hash< auto > login, *reference< hash< auto > > info, *bool refresh)
Perform OAuth2 authentication.
*string getToken()
Returns any token set for the connection.
string oauth2_app
OAuth2 app name.
Definition RestClient.qm.dox.h:453
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:435
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:473
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:471
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:405
string oauth2_redirect_url
OAuth2 redirect URL.
Definition RestClient.qm.dox.h:421
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
transient *code alt_token_signer
To use to sign requests to the any alt token URL.
Definition RestClient.qm.dox.h:476
string token
Any token set for the connection; will be passed as a bearer token (Authorization: Bearer ....
Definition RestClient.qm.dox.h:431
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:445
transient *string alt_token_signer_header
The header for the alt token signer.
Definition RestClient.qm.dox.h:478
setupUserPassword(hash< auto > opts)
Setup username and password consistently.
*LoggerInterface getLogger()
Returns the logger interface for logging.
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:423
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:407
*hash< auto > oauth2_alt_url_subst
Alternate OAuth2 URL substitution info.
Definition RestClient.qm.dox.h:425
bool requiresOAuth2Token()
Returns True if the client requires an OAuth2 token.
string oauth2_client_secret
OAuth2 client secret.
Definition RestClient.qm.dox.h:409
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:429
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:443
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:427
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:417
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:455
*softlist< string > oauth2_scopes
OAuth2 scope.
Definition RestClient.qm.dox.h:411
replaceDefaultHeaders(*hash< auto > hdr)
replaces default headers
setAltTokenSigner(code signer, string signer_header)
Sets alt token signer code and the header for it.
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)
Makes a REST request and returns the result.
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:402
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:415
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:322
string oauth2_auth_url
OAuth2 auth URL.
Definition RestClient.qm.dox.h:419
string refresh_token
Any refresh token granted to the client.
Definition RestClient.qm.dox.h:433
string custom_token_location
REST custom token location.
Definition RestClient.qm.dox.h:469
string username
username for authentication
Definition RestClient.qm.dox.h:400
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:457
string custom_token_auth
REST custom token auth method.
Definition RestClient.qm.dox.h:463
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.
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)
sends the outgoing HTTP message and recodes the response to data
class for REST HTTP connections; returns RestClient::RestClient objects
Definition RestClient.qm.dox.h:1559
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:1596
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:1576
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:1563
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:1573
*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:1579
bool needs_auth
Connections needs authorization?
Definition RestClient.qm.dox.h:1566
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.
transient *code alt_token_signer
To use to sign requests to the any alt token URL.
Definition RestClient.qm.dox.h:1594
*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:1590
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:1583
clearAltTokenSigner()
Clears alt token signer code and the header for it.
const ConnectionScheme
Connection entry info.
Definition RestClient.qm.dox.h:1569
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:1599
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:1977
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition RestClient.qm.dox.h:1987
*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:2033
RestConnection conn
The REST connection.
Definition RestClient.qm.dox.h:2000
string state
Current state.
Definition RestClient.qm.dox.h:2027
string path
The URI path to use.
Definition RestClient.qm.dox.h:2018
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:1984
hash< auto > real_opts
RestClient options.
Definition RestClient.qm.dox.h:2006
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition RestClient.qm.dox.h:1981
RestClient rc
The RestClient object to use for polling I/O.
Definition RestClient.qm.dox.h:2003
const SPS_COMPLETE
Complete state.
Definition RestClient.qm.dox.h:1996
bool use_path_as_is
Use path directly / ping path already prepared.
Definition RestClient.qm.dox.h:2036
*hash< auto > headers
Headers to send.
Definition RestClient.qm.dox.h:2024
const SPS_REST_PING
Execute ping request.
Definition RestClient.qm.dox.h:1993
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition RestClient.qm.dox.h:2009
*auto body
The message body to send.
Definition RestClient.qm.dox.h:2021
const SPS_CUSTOM_GET_TOKEN
Custom refresh token state.
Definition RestClient.qm.dox.h:1990
bool goal_reached
Goal reached flag.
Definition RestClient.qm.dox.h:2012
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition RestClient.qm.dox.h:2015
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:280
Hash to use for generating authorization code requests.
Definition RestClient.qm.dox.h:284
*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:289
*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:292
string response_type
The response type value to use in the request.
Definition RestClient.qm.dox.h:286
*string state
The state value to use in the request.
Definition RestClient.qm.dox.h:295