1#ifndef TENDUKE_EXAMPLES_UTILS_H
2#define TENDUKE_EXAMPLES_UTILS_H
4#include "licensing/checkout/LicenseCheckoutResponse.h"
5#include "licensing/release/LicenseReleaseResponse.h"
6#include "licensing/renew/LicenseRenewResponse.h"
7#include "oidc/OIDCState.h"
16 const std::string DEMO_DEPLOYMENT_URL =
"https://your-deployment-url-here";
18 const std::string HTTP_MESSAGE_WHEN_LOGIN_SUCCEEDS =
20 "Content-Type: text/html; charset=utf-8\n"
24 " <title>Login successful, you can close the tab</title>\n"
27 " display: flex; flex-direction: column; justify-content: center;\n"
28 " min-height: 100vh;\n"
31 " text-align: center;\ns"
36 " <div class=\"center\">\n"
37 " <H1>Login successful</H1>\n"
38 " <p>You can close this tab now</p>\n"
62 auto fromEnvironment = std::getenv(
"XD_DEPLOYMENT_URL");
63 if (fromEnvironment == NULL) {
64 return ::tenduke::eg::DEMO_DEPLOYMENT_URL;
66 return fromEnvironment;
70 const std::shared_ptr<const tenduke::oidc::OIDCState> &state,
71 std::int64_t expiresAt
77 const std::shared_ptr<const tenduke::oidc::OIDCState> &state,
78 const std::string& refreshToken
83 void dumpToConsole(const ::tenduke::ee::licensing::Lease &lease)
87 <<
": id=" << lease.licenseId
88 <<
", leaseId = " << lease.leaseId
89 <<
", expires = " << lease.leaseExpiresEpochS
90 << (lease.consumedVersion.empty() ?
"" :
" , version = " + lease.consumedVersion)
91 <<
", licenseId = " << lease.licenseId
95 void dumpToConsole(
const std::vector<tenduke::ee::licensing::Lease> &leases)
97 for (
auto const &lease : leases) {
102 void dumpToConsole(
const std::map<std::string, tenduke::ee::licensing::Lease> &leases)
104 std::vector<tenduke::ee::licensing::Lease> list;
105 list.reserve(leases.size());
106 for (
auto const &lease : leases) {
107 list.push_back(lease.second);
114 if (response.
leases.empty()) {
115 std::cout <<
"No items successfully checked out" << std::endl;
118 std::cout <<
"Successfully checked out items:" << std::endl;
120 dumpToConsole(response.
leases);
123 std::cout <<
"Failed items:" << std::endl;
124 for (
auto const &failedItem: response.errors) {
125 std::cout <<
" - " << failedItem.first <<
":" << std::endl;
126 std::cout <<
" error code: " << failedItem.second.getErrorCode() << std::endl;
127 std::cout <<
" error key: " << failedItem.second.getErrorKey() << std::endl;
128 std::cout <<
" error message: " << failedItem.second.getErrorMessage() << std::endl;
129 std::cout <<
" technical: " << failedItem.second.getErrorTechnical() << std::endl;
136 if (response.
leases.empty()) {
137 std::cout <<
"No leases successfully renewed" << std::endl;
140 std::cout <<
"Successfully renewed leases:" << std::endl;
142 dumpToConsole(response.
leases);
145 std::cout <<
"Failed items:" << std::endl;
146 for (
auto const &failedItem: response.errors) {
147 std::cout <<
" - " << failedItem.first <<
":" << std::endl;
148 std::cout <<
" error code: " << failedItem.second.getErrorCode() << std::endl;
149 std::cout <<
" error key: " << failedItem.second.getErrorKey() << std::endl;
150 std::cout <<
" error message: " << failedItem.second.getErrorMessage() << std::endl;
151 std::cout <<
" technical: " << failedItem.second.getErrorTechnical() << std::endl;
160 std::cout <<
"No leases successfully released" << std::endl;
163 std::cout <<
"Successfully released leases:" << std::endl;
165 for (
auto const &leaseId: response.leaseIds) {
166 std::cout <<
" * " << leaseId << std::endl;
170 std::cout <<
"Failed leases:" << std::endl;
171 for (
auto const &failedItem: response.errors) {
172 std::cout <<
" - " << failedItem.first <<
":" << std::endl;
173 std::cout <<
" error code: " << failedItem.second.getErrorCode() << std::endl;
174 std::cout <<
" error key: " << failedItem.second.getErrorKey() << std::endl;
175 std::cout <<
" error message: " << failedItem.second.getErrorMessage() << std::endl;
176 std::cout <<
" technical: " << failedItem.second.getErrorTechnical() << std::endl;
183 std::cout <<
"OIDC-state:" << std::endl;
185 std::cout <<
" - ID-token: " << std::endl;
188 std::cout <<
" - access token: " << state.
getAccessToken() << std::endl;
190 std::cout <<
" - refresh token: " <<state.
getRefreshToken() << std::endl;
193 std::cout <<
" - not refreshable" << std::endl;
195 std::cout <<
" - expires: " << state.
getExpiresAt() << std::endl;
198 void dumpToConsole(
const std::shared_ptr<const tenduke::oidc::OIDCState> &state)
200 if (state ==
nullptr) {
201 std::cout <<
"No OIDC state" << std::endl;
204 dumpToConsole(*state);
Response from license checkout request.
Definition LicenseCheckoutResponse.h:24
const std::map< std::string, tenduke::ee::licensing::Lease > leases
Leases, that is, successfully checked out licenses.
Definition LicenseCheckoutResponse.h:48
Response from tenduke::ee::licensing::LicenseReleaseRequest.
Definition LicenseReleaseResponse.h:18
const std::vector< std::string > leaseIds
Id's of successfully released leases.
Definition LicenseReleaseResponse.h:44
Response from license renew -request.
Definition LicenseRenewResponse.h:14
bool hasErrors() const
Checks if there are any errors.
Definition LicensingResponse.h:42
const std::string & getIssuer() const
Returns "Issuer", "iss"-claim.
Definition JWT.cpp:71
const std::string & getSubject() const
Returns "Subject", "sub"-claim.
Definition JWT.cpp:77
const std::string & getRefreshToken() const override
Returns the refresh token.
Definition OAuthStateImpl.h:55
bool isRefreshable() const override
Returns true if the state is refreshable (i.e.
Definition OAuthStateImpl.h:98
std::int64_t getExpiresAt() const override
Returns timestamp (as epoch seconds) when the current access token expires.
Definition OAuthStateImpl.h:60
const std::string & getAccessToken() const override
Returns the access token.
Definition OAuthStateImpl.h:50
void setExpiresAt(std::int64_t newExpiresAt) override
Set the "expires at".
Definition OAuthStateImpl.h:108
void setRefreshToken(const std::string &newRefreshToken) override
Set the refresh token.
Definition OAuthStateImpl.h:114
Container of OIDC state, describing the user session.
Definition OIDCState.h:17
const tenduke::oidc::IdToken & getIdToken() const
Returns the contained ID-token.
Definition OIDCState.h:64
Examples.
Definition demo_utils.h:14
std::string getDeploymentURL(int argc, char **argv)
Returns deployment URL.
Definition demo_utils.h:60
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4