Qore RestClient Module Reference 2.0.1
Loading...
Searching...
No Matches
RestClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* RestClient.qm Copyright (C) 2013 - 2023 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
239namespace RestClient {
241
243public hashdecl AuthCodeInfo {
245 string response_type = "code";
246
249
251 *list<string> scopes;
252
254 *string state;
255};
256
258class RestClient : public Qore::HTTPClient, public Logger::LoggerWrapper, public ConnectionProvider::UpdateOptionsInterface {
259
260public:
262 const DataSerializationSupport = {
263%ifndef NoJson
264 "json": MimeTypeJson,
265%endif
266%ifndef NoYaml
267 "yaml": MimeTypeYaml,
268%endif
269%ifndef NoXml
270 "xml": MimeTypeXml,
271 "rawxml": MimeTypeXmlApp,
272%endif
273 "url": MimeTypeFormUrlEncoded,
274 "text": MimeTypeText,
275 "bin": MimeTypeOctetStream,
276 };
277
278 const DeserializeYaml = {
279 "code": "yaml",
280 "in": \parse_yaml(),
281 };
282 const DeserializeXml = {
283 "code": "xml",
284 "arg": True,
285 "in": hash<auto> sub (string xml, reference<string> type) {
286 try {
287 on_success type = "xml";
288 return parse_xmlrpc_value(xml);
289 } catch (hash<ExceptionInfo> ex) {
290 try {
291 on_success type = "rawxml";
292 return parse_xml(xml);
293 } catch () {
294 rethrow;
295 }
296 }
297 },
298 };
299
301 const AcceptList = ...;
302
303
305 const Accept = AcceptList.join(",");
306
308 const AcceptMap = map {$1: True}, AcceptList;
309
311 const Version = "2.0";
312
314 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
315
317 const DefaultHeaders = {
318 "Accept": Accept,
319 "User-Agent": RestClient::VersionString,
320 };
321
323 const DefaultOAuth2RedirectUrl = "auto";
324
326 const DefaultOptions = {
327 "oauth2_redirect_url": DefaultOAuth2RedirectUrl,
328 };
329
331
341 const DataSerializationOptions = {
342 "auto": True,
343%ifndef NoJson
344 "json": True,
345%endif
346%ifndef NoYaml
347 "yaml": True,
348%endif
349%ifndef NoXml
350 "rawxml": True,
351 "xml": True,
352%endif
353 "url": True,
354 "text": True,
355 "bin": True,
356 };
357
359
365 const EncodingSupport = {
366 "gzip": {
367 "ce": "gzip",
368 "func": \gzip(),
369 },
370 "bzip2": {
371 "ce": "bzip2",
372 "func": \bzip2(),
373 },
374 "deflate": {
375 "ce": "deflate",
376 "func": \compress(),
377 },
378 "identity": {
379 "ce": NOTHING,
380 },
381 };
382
384 const CompressionThreshold = 1024;
385
387
389 const OAuth2GrantOptions = {
390 "authorization_code": (
391 "oauth2_auth_url",
392 "oauth2_client_id",
393 "oauth2_client_secret",
394 "oauth2_redirect_url",
395 "oauth2_token_url",
396 ),
397 "client_credentials": (
398 "oauth2_client_id",
399 "oauth2_client_secret",
400 "oauth2_token_url",
401 ),
402 "password": (
403 "oauth2_client_id",
404 "oauth2_client_secret",
405 "oauth2_token_url",
406 ),
407 };
408
410 const OAuth2AuthHeaders = {
411 // this will ensure that OAuth2 servers do not prefer XML or other serialization with a different data
412 # format (ex: the Salesforce OAuth2 server)
413 "Accept": MimeTypeFormUrlEncoded + "," + MimeTypeJson,
414 };
415
417 const MinimumTokenRefresh = 1m;
418
419protected:
420 // headers to send with every request
421 hash<auto> headers;
422 // data serialization code
423 string ds;
424 // serialization content type
425 string sct;
426 // send content encoding hash
427 *hash<auto> seh;
428 // REST schema validator
430 // no_charset option
431 *bool noCharset;
432
434 string username;
436 string password;
437
445 *softlist<string> oauth2_scopes;
447 *hash<auto> oauth2_auth_args;
457 string token;
461 bool oauth2_auto_refresh = True;
464
465public:
466
468
566 constructor(*hash<auto> opts, *softbool do_not_connect) ;
567
568
570
573
574
576
589 setSerialization(string data = 'auto');
590
591
593
610 setSendEncoding(string enc = 'auto');
611
612
614
631 setContentEncoding(string enc = 'auto');
632
633
635
651 addDefaultHeaders(hash<auto> h);
652
653
655
668 hash<auto> getDefaultHeaders();
669
670
672
677 replaceDefaultHeaders(*hash<auto> hdr);
678
679
681
697
698
700
713
714
716
770 hash<auto> get(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
771
772
774
825 hash<auto> put(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
826
827
829
880 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
881
882
884
935 hash<auto> post(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
936
937
939
990 hash<auto> del(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
991
992
994
999
1000
1002
1005
1006
1008
1011
1012
1014
1017
1018
1020
1022 setToken(string token_type, string token, *string refresh_token);
1023
1024
1026
1029
1030
1032
1034 *string getToken();
1035
1036
1038
1040 AbstractPollOperation startOAuth2PollSendRecv();
1041
1042
1044
1046 AbstractPollOperation startOAuth2PollRefreshToken();
1047
1048
1050
1095 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1096
1097
1099protected:
1100 hash<auto> doRequestIntern(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr, *string assume_content_type);
1101public:
1102
1103
1105
1112 prepareToSend(string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1113
1114
1116
1118 hash<auto> doValidatedRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1119
1120
1122
1129 hash<auto> processRestResponse(hash<auto> resp, string method, string path, *reference<hash<auto>> info);
1130
1131
1133
1135 hash<auto> gotOAuth2LoginInfo(hash<auto> h);
1136
1137
1139
1141protected:
1142 setOAuth2LoginInfo(hash<auto> h);
1143public:
1144
1145
1147
1149protected:
1150 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h);
1151public:
1152
1153
1155
1157protected:
1158 setupAuth(hash<auto> opts);
1159public:
1160
1161
1163
1165protected:
1166 checkOAuth2Options(hash<auto> opts);
1167public:
1168
1169
1171
1173protected:
1174 hash<auto> loginIntern(*reference<hash<auto>> info);
1175public:
1176
1177
1179
1181protected:
1182 AbstractPollOperation startOAuth2AuthPoll(hash<auto> login);
1183public:
1184
1185
1187
1189protected:
1190 hash<auto> oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1191public:
1192
1193
1195
1197protected:
1198 hash<auto> doOAuth2LoginRequest(string url, hash<auto> login, *reference<hash<auto>> info);
1199public:
1200
1201
1203
1205protected:
1207public:
1208
1209
1211
1213protected:
1214 hash<auto> getOAuth2LoginInfo(string grant_type);
1215public:
1216
1217
1219
1221protected:
1223public:
1224
1225
1227protected:
1228 nothing prepareMsg(string method, string path, reference<auto> body, reference<hash<auto>> hdr, string ct = 'Content-Type');
1229public:
1230
1231
1233protected:
1234 nothing preparePath(reference<string> path);
1235public:
1236
1237
1239protected:
1240 checkLogin(*reference<hash<auto>> info);
1241public:
1242
1243
1245protected:
1246 hash<auto> sendAndDecodeResponse(*data body, string m, string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *string assume_content_type);
1247public:
1248
1249
1251protected:
1252 static decodeError(hash<auto> h, *reference<hash<auto>> info);
1253public:
1254
1255
1257private:
1258 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1259public:
1260
1261
1262}; // class RestClient
1263
1265
1338
1339public:
1341 hash<auto> real_opts;
1342
1344 const ConnectionScheme = <ConnectionSchemeInfo>{
1345 "cls": Class::forName("RestConnection"),
1346 "options": HttpConnection::ConnectionScheme.options + {
1347 "content_encoding": <ConnectionOptionInfo>{
1348 "type": "string",
1349 "desc": "this sets the send encoding (if the `send_encoding` option is not set) and the "
1350 "response encoding to request",
1351 "allowed_values": (
1352 <AllowedValueInfo>{
1353 "value": "gzip",
1354 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1355 }, <AllowedValueInfo>{
1356 "value": "bzip2",
1357 "desc": "use bzip2 encoding",
1358 }, <AllowedValueInfo>{
1359 "value": "deflate",
1360 "desc": "use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1361 }, <AllowedValueInfo>{
1362 "value": "identity",
1363 "desc": "use no content encoding",
1364 },
1365 ),
1366 },
1367 "data": <ConnectionOptionInfo>{
1368 "type": "string",
1369 "desc": "data serialization options",
1370 "allowed_values": (
1371 <AllowedValueInfo>{
1372 "value": "auto",
1373 "desc": "prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1374 }, <AllowedValueInfo>{
1375 "value": "bin",
1376 "desc": "for binary message bodies without data serialization",
1377 }, <AllowedValueInfo>{
1378 "value": "json",
1379 "desc": "use JSON serialization",
1380 }, <AllowedValueInfo>{
1381 "value": "rawxml",
1382 "desc": "use raw XML serialization",
1383 }, <AllowedValueInfo>{
1384 "value": "text",
1385 "desc": "use only plain text; no serialization is used",
1386 }, <AllowedValueInfo>{
1387 "value": "url",
1388 "desc": "for URL-encoded message bodies",
1389 }, <AllowedValueInfo>{
1390 "value": "xml",
1391 "desc": "use only XML-RPC serialization",
1392 }, <AllowedValueInfo>{
1393 "value": "yaml",
1394 "desc": "use only YAML serialization",
1395 },
1396 ),
1397 "default_value": "auto",
1398 },
1399 "headers": <ConnectionOptionInfo>{
1400 "type": "hash",
1401 "desc": "an optional hash of headers to send with every request, these can also be "
1402 "overridden in request method calls",
1403 },
1404 "oauth2_auth_args": <ConnectionOptionInfo>{
1405 "type": "hash",
1406 "desc": "Optional arguments for authentication requests for the `authorization_code` grant type; "
1407 "ignored if the `token` option is set. Note that the `authorization_code` grant type "
1408 "requires external user authorization to acquire an access token",
1409 },
1410 "oauth2_auth_url": <ConnectionOptionInfo>{
1411 "type": "string",
1412 "desc": "The OAuth2 authorization URL for the `authorization_code` grant type; ignored "
1413 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1414 "external user authorization to acquire an access token",
1415 },
1416 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1417 "type": "bool",
1418 "desc": "If OAuth2 tokens should be automatically refreshed",
1419 "default_value": True,
1420 },
1421 "oauth2_client_id": <ConnectionOptionInfo>{
1422 "type": "string",
1423 "desc": "The OAuth2 client ID; ignored if the `token` option is set",
1424 },
1425 "oauth2_client_secret": <ConnectionOptionInfo>{
1426 "type": "string",
1427 "desc": "the OAuth2 client secret; ignored if the `token` option is set",
1428 "sensitive": True,
1429 },
1430 "oauth2_grant_type": <ConnectionOptionInfo>{
1431 "type": "string",
1432 "desc": "The OAuth2 grant type; ignored if the `token` option is set",
1433 "allowed_values": (
1434 <AllowedValueInfo>{
1435 "value": "authorization_code",
1436 "desc": "OAuth2 2.0 authorization code grant "
1437 "([RFC 6749 authorization code grant]"
1438 "(https://datatracker.ietf.org/doc/html/rfc6749//section-4.1)); this grant type "
1439 "requires external user authorization to acquire an access token; the "
1440 "`oauth2_auth_url` must be set to inform external code where to request "
1441 "authorization from the external authorization server",
1442 }, <AllowedValueInfo>{
1443 "value": "client_credentials",
1444 "desc": "OAuth2 2.0 client credentials grant "
1445 "([RFC 6749 client credentials grant]"
1446 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.4))",
1447 }, <AllowedValueInfo>{
1448 "value": "password",
1449 "desc": "OAuth2 2.0 legacy password grant "
1450 "([RFC 6749 password grant]"
1451 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.3))",
1452 },
1453 ),
1454 },
1455 "oauth2_redirect_url": <ConnectionOptionInfo>{
1456 "type": "string",
1457 "desc": "The OAuth2 redirect URL for the `authorization_code` grant type; ignored "
1458 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1459 "external user authorization to acquire an access token; the special value `auto` (the "
1460 "default) is meant to be interpreted by servers that implement OAuth2 authorization code "
1461 "client handling",
1462 "default_value": "auto",
1463 },
1464 "oauth2_refresh_token": <ConnectionOptionInfo>{
1465 "type": "string",
1466 "desc": "the OAuth2 refresh token, if any (complements option `token`)",
1467 "sensitive": True,
1468 },
1469 "oauth2_scopes": <ConnectionOptionInfo>{
1470 "type": "list",
1471 "desc": "Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1472 },
1473 "oauth2_token_url": <ConnectionOptionInfo>{
1474 "type": "string",
1475 "desc": "The token URL for OAuth2 flows; ignored if the `token` option is set",
1476 },
1477 "password": <ConnectionOptionInfo>{
1478 "type": "string",
1479 "desc": "The password for authentication; only used if no username or password is set in the URL "
1480 "and if the `username` option is also used; conflicts with the `token` option",
1481 "sensitive": True,
1482 },
1483 "ping_method": <ConnectionOptionInfo>{
1484 "type": "string",
1485 "desc": "The HTTP method to use for an advanced ping; this and `ping_path` must be set to make "
1486 "an HTTP request as a part of the socket polling ping operation; must be a valid HTTP method "
1487 "name",
1488 },
1489 "ping_path": <ConnectionOptionInfo>{
1490 "type": "string",
1491 "desc": "The URI path to use for an advanced ping; this and `ping_method` must be made to make "
1492 "an HTTP request as a part of the socket polling ping operation. If the value for this "
1493 "option begins with a `/` character, then it replaces any connection path for the REST "
1494 "client, otherwise the value is appended to the connection path for the REST client.",
1495 },
1496 "ping_headers": <ConnectionOptionInfo>{
1497 "type": "hash",
1498 "desc": "Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1499 "one of `ping_method` and `ping_path` are not set",
1500 },
1501 "ping_body": <ConnectionOptionInfo>{
1502 "type": "any",
1503 "desc": "Any message body to send when performing an advanced ping operation; ignored if either "
1504 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1505 },
1506 "send_encoding": <ConnectionOptionInfo>{
1507 "type": "string",
1508 "desc": "this sets the send encoding",
1509 "allowed_values": (
1510 <AllowedValueInfo>{
1511 "value": "gzip",
1512 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1513 }, <AllowedValueInfo>{
1514 "value": "bzip2",
1515 "desc": "use bzip2 encoding",
1516 }, <AllowedValueInfo>{
1517 "value": "deflate",
1518 "desc": "use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1519 }, <AllowedValueInfo>{
1520 "value": "identity",
1521 "desc": "use no content encoding",
1522 },
1523 ),
1524 },
1525 "swagger": <ConnectionOptionInfo>{
1526 "type": "file-as-string",
1527 "desc": "the location of a Swagger schema to use for message validation; processed with "
1528 "`FileLocationHandler::getTextFileFromLocation()` "
1529 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1530 "freeform": True,
1531 },
1532 "swagger_base_path": <ConnectionOptionInfo>{
1533 "type": "string",
1534 "desc": "in case a REST validator is used, the base path in the schema can be overridden "
1535 "with this option (applies to any REST validator; not just Swagger validators)",
1536 },
1537 "swagger_lax_parsing": <ConnectionOptionInfo>{
1538 "type": "bool",
1539 "desc": "try to parse invalid Swagger schemas",
1540 },
1541 "token": <ConnectionOptionInfo>{
1542 "type": "string",
1543 "desc": "Any bearer token to use for the connection; will be passed as "
1544 "`Authorization: Bearer ...` in request headers; this option cannot be used with username "
1545 "and password options or authentication information in the URL; if this option is set then "
1546 "OAuth2 options are ignored",
1547 "sensitive": True,
1548 },
1549 "token_type": <ConnectionOptionInfo>{
1550 "type": "string",
1551 "desc": "The type of `token` to use for the `Authentication` header; ignored if no `token` "
1552 "option is set",
1553 "default_value": "Bearer",
1554 },
1555 "username": <ConnectionOptionInfo>{
1556 "type": "string",
1557 "desc": "The username for authentication; only used if no username or password is set in the URL "
1558 "and if the `password` option is also used; conflicts with the `token` option",
1559 },
1560 "validator": <ConnectionOptionInfo>{
1561 "type": "any",
1562 "desc": "an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1563 "`swagger`",
1564 },
1565 },
1566 };
1567
1569 const Options = map {$1: True}, keys ConnectionScheme.options;
1570
1572 const OptionList = keys ConnectionScheme.options;
1573
1576
1577
1579 const OAuth2Options = ...;
1580
1581
1583
1586 const RCF_OAUTH2_AUTH_CODE = "oauth2-auth-code";
1587
1588protected:
1590 hash<string, bool> features = {
1591 CF_LOGGER: True,
1592 };
1593
1594public:
1595
1597
1610 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1611 ;
1612
1613
1615
1617 string getOAuth2OptionName(string opt);
1618
1619
1621
1625 object getPollImpl();
1626
1627
1629
1633 hash<auto> getOptions();
1634
1635
1637 string getType();
1638
1639
1641
1643 hash<auto> getOAuth2Options();
1644
1645
1647
1649 hash<auto> processOAuth2TokenResponse(hash<auto> resp);
1650
1651
1653
1660
1661
1663
1668
1669
1671
1677
1678
1680
1682 static hash<auto> processOptions(*hash<auto> opts);
1683
1685
1692 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
1693
1694
1696 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1697 is to return a full URL
1698
1699 @since %RestClient 2.0
1700 */
1701 string getAuthUrl(*bool allow_relative);
1702
1703
1705 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1706 is to return a full URL
1707
1708 @since %RestClient 2.0
1709 */
1710 string getTokenUrl(*bool allow_relative);
1711
1712
1714 /*
1715 @since %RestClient 2.0
1716 */
1717protected:
1718 static softstring getUriValue(auto v);
1719public:
1720
1721
1723protected:
1724 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1725public:
1726
1727
1729protected:
1731public:
1732
1733
1735
1743protected:
1744 RestClient getImpl(bool connect = True, *hash<auto> rtopts);
1745public:
1746
1747
1749
1751protected:
1753public:
1754
1755
1757
1759protected:
1760 *hash<string, bool> getFeaturesImpl();
1761public:
1762
1763
1765protected:
1767public:
1768
1769
1771protected:
1772 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
1773public:
1774
1775};
1776
1778
1781
1782public:
1784 const SPS_GET_SWAGGER = 'get-swagger';
1785
1787 const SPS_OAUTH2_GET_TOKEN = "oauth2-get-token";
1788
1790 const SPS_OAUTH2_REFRESH_TOKEN = "oauth2-refresh-token";
1791
1793 const SPS_REST_PING = "rest-ping";
1794
1796 const SPS_COMPLETE = "complete";
1797
1798protected:
1801
1803 hash<auto> real_opts;
1804
1806 AbstractPollOperation poller;
1807
1809 bool goal_reached = False;
1810
1812 string method;
1813
1815 string path;
1816
1818 *auto body;
1819
1821 *hash<auto> headers;
1822
1824 string state;
1825
1827 Mutex m();
1828
1831
1834
1835public:
1836
1839
1840
1842
1844 string getGoal();
1845
1846
1848
1850 string getState();
1851
1852
1854
1857
1858
1860 *hash<SocketPollInfo> continuePoll();
1861
1862
1863protected:
1864 checkOtherStates();
1865public:
1866
1867
1868protected:
1869 gotOAuth2LoginInfo(hash<auto> h);
1870public:
1871
1872
1873protected:
1874 doStartGetToken();
1875public:
1876
1877
1878protected:
1879 doStartRefresh();
1880public:
1881
1882
1883protected:
1884 doStartPing();
1885public:
1886
1887};
1888};
*string getToken()
Returns any token set for the connection.
*hash< auto > getUpdateOptionsAfterLogin(hash< auto > h)
Returns options to update after an OAuth2 login.
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.
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:439
string oauth2_redirect_url
OAuth2 redirect URL.
Definition: RestClient.qm.dox.h:451
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:314
hash< auto > sendAndDecodeResponse(*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors, *string assume_content_type)
sends the outgoing HTTP message and recodes the response to data
hash< auto > loginIntern(*reference< hash< auto > > info)
Authenticates with OAuth2 if configured.
constructor(*hash< auto > opts, *softbool do_not_connect)
calls the base class HTTPClient constructor and optionally connects to the REST server
string token
Any token set for the connection; will be passed as a bearer token (Authorization: Bearer ....
Definition: RestClient.qm.dox.h:457
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
checkOAuth2Options(hash< auto > opts)
Validates and sets any OAuth2 options.
setContentEncoding(string enc='auto')
sets the request and desired response encoding for the object; see EncodingSupport for valid options
hash< auto > gotOAuth2LoginInfo(hash< auto > h)
Called when OAuth2 login information has been received.
string oauth2_token_url
OAuth2 token URL.
Definition: RestClient.qm.dox.h:453
nothing preparePath(reference< string > path)
sets up the path for the HTTP request URI
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.
hash< auto > doOAuth2LoginRequest(string url, hash< auto > login, *reference< hash< auto > > info)
Returns the deserialized response body of an OAuth2 authorization / token request.
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.
string getTokenType()
Returns the token type for any token.
setupAuth(hash< auto > opts)
Sets up authentication info.
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.
string oauth2_client_id
OAuth2 client ID.
Definition: RestClient.qm.dox.h:441
bool requiresOAuth2Token()
Returns True if the client requires an OAuth2 token.
hash< auto > oauth2Auth(hash< auto > login, *reference< hash< auto > > info)
Perform OAuth2 authentication.
string oauth2_client_secret
OAuth2 client secret.
Definition: RestClient.qm.dox.h:443
string token_type
The token type, if any.
Definition: RestClient.qm.dox.h:455
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
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.
setSendEncoding(string enc='auto')
change the data content encoding (compression) option for the object
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.
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.
*softlist< string > oauth2_scopes
OAuth2 scope.
Definition: RestClient.qm.dox.h:445
replaceDefaultHeaders(*hash< auto > hdr)
replaces default headers
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
setToken(string token_type, string token, *string refresh_token)
Sets a token for authentication.
string password
password for authentication
Definition: RestClient.qm.dox.h:436
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 args.
Definition: RestClient.qm.dox.h:447
string getSerialization()
returns the current data serialization format currently in effect for the object
*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:311
string oauth2_auth_url
OAuth2 auth URL.
Definition: RestClient.qm.dox.h:449
string refresh_token
Any refresh token granted to the client.
Definition: RestClient.qm.dox.h:459
string username
username for authentication
Definition: RestClient.qm.dox.h:434
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:463
hash< auto > doRequestIntern(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr, *string assume_content_type)
Makes a REST request and returns the result.
setValidator(RestSchemaValidator::AbstractRestSchemaValidator validator)
Sets a new REST schema validator.
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:1337
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
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:1572
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the RestConnection connection object
hash< auto > real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:1341
const Options
object connection options
Definition: RestClient.qm.dox.h:1569
hash< auto > getOAuth2Options()
Returns OAuth2 options in a standard format.
*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.
static softstring getUriValue(auto v)
Returns a value for use as a URI parameter.
const OAuth2AuthRequestOptions
Options required for an OAuth2 authorization request.
Definition: RestClient.qm.dox.h:1575
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
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.
Qore::AbstractPollOperation startPollConnect()
Called to start a non-blocking polling ping operation on the remote REST server.
object getPollImpl()
Returns an unconnected object for a non-blocking poll operation.
*hash< string, bool > getFeaturesImpl()
Returns a list of connection-defined features.
const RCF_OAUTH2_AUTH_CODE
RestClient feature: OAuth2 Auth Code support.
Definition: RestClient.qm.dox.h:1586
hash< auto > processOAuth2TokenResponse(hash< auto > resp)
Processes the OAuth2 token response.
setChildCapabilities()
Sets child data provider capabilities.
RestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a RestClient object
static hash< auto > processOptions(*hash< auto > opts)
processes options for the constructor
hash< auto > getOptions()
gets options
const OAuth2Options
All OAuth2 options.
Definition: RestClient.qm.dox.h:1579
const ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:1344
hash< string, bool > features
Hash of supported features.
Definition: RestClient.qm.dox.h:1590
string getType()
returns "rest"
string getTokenUrl(*bool allow_relative)
Returns the OAuth2 token URL or throws an exception if not set.
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling I/O class with OAuth2 authentication.
Definition: RestClient.qm.dox.h:1780
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition: RestClient.qm.dox.h:1790
*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:1830
string state
Current state.
Definition: RestClient.qm.dox.h:1824
constructor(RestClient rc, hash< auto > real_opts)
Creates the poller with the REST client and option hash.
string path
The URI path to use.
Definition: RestClient.qm.dox.h:1815
string getGoal()
Returns the goal.
const SPS_OAUTH2_GET_TOKEN
OAuth2 get token state.
Definition: RestClient.qm.dox.h:1787
hash< auto > real_opts
RestClient options.
Definition: RestClient.qm.dox.h:1803
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition: RestClient.qm.dox.h:1784
RestClient rc
The RestClient object to use for polling I/O.
Definition: RestClient.qm.dox.h:1800
const SPS_COMPLETE
Complete state.
Definition: RestClient.qm.dox.h:1796
bool use_path_as_is
Use path directly / ping path already prepared.
Definition: RestClient.qm.dox.h:1833
*hash< auto > headers
Headers to send.
Definition: RestClient.qm.dox.h:1821
const SPS_REST_PING
Execute ping request.
Definition: RestClient.qm.dox.h:1793
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1806
*auto body
The message body to send.
Definition: RestClient.qm.dox.h:1818
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1809
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition: RestClient.qm.dox.h:1812
Mutex m()
Lock for atomicity.
string type(auto arg)
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:239
Hash to use for generating authorization code requests.
Definition: RestClient.qm.dox.h:243
*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:248
*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:251
string response_type
The response type value to use in the request.
Definition: RestClient.qm.dox.h:245
*string state
The state value to use in the request.
Definition: RestClient.qm.dox.h:254