10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
AbstractClientFactory.h
1#ifndef TENDUKE_EE_BASECLIENTFACTORY_H
2#define TENDUKE_EE_BASECLIENTFACTORY_H
3
4#include "./createTendukeClient.h"
5#include "./TendukeClient.h"
6#include "./config/ClientProperties.h"
7#include "./state/DeserializeStateFromJSON.h"
8#include "createDefaultTendukeServices.h"
9#include "ServiceConfiguration.h"
10#include "TendukeServices.h"
11#include "log/log.h"
12#include "oidc/session/OIDCLogin.h"
13
14#include <memory>
15#include <string>
16
17namespace tenduke { namespace ee {
18
24template<class P>
26{
27public:
28 virtual ~AbstractClientFactory() = default;
29
39 const std::string &clientId,
40 const ::tenduke::ServiceConfiguration &serviceConfiguration = ::tenduke::ServiceConfiguration()
41 )
42 : services(::tenduke::createDefaultTendukeServices(clientId, serviceConfiguration))
43 {}
44
51 explicit AbstractClientFactory(const ::tenduke::TendukeServices &services) : services(services) {}
52
53public:
68 virtual std::unique_ptr<::tenduke::ee::TendukeClient> createClient(
69 const ::tenduke::ee::ClientProperties &clientProperties,
70 const std::string &serviceUrl,
71 const ::tenduke::oauth::OAuthBackendConfiguration &oauthBackendConfiguration,
72 const ::tenduke::oidc::OIDCConfiguration &oidcConfiguration,
73 const P &authenticationConfiguration,
74 const std::string &initialStateAsJSON = {}
75 ) const
76 {
77 auto oauthConfiguration = mkOAuthConfiguration(oauthBackendConfiguration, authenticationConfiguration);
78 auto oidcConfig = std::shared_ptr<::tenduke::oidc::OIDCConfiguration>(new ::tenduke::oidc::OIDCConfiguration(oidcConfiguration));
79
80 return ::tenduke::ee::createClient(
81 services,
82 mkLicensingConfiguration(serviceUrl, clientProperties, oidcConfiguration),
83 oauthConfiguration,
84 oidcConfig,
85 createOIDCLoginService(oauthConfiguration, oidcConfig, authenticationConfiguration),
86 authenticationConfiguration.oidcSessionConfiguration,
87 ::tenduke::ee::DeserializeStateFromJSON(services.jwtParser,services.jsonParser).from(initialStateAsJSON)
88 );
89 }
90
105 std::unique_ptr<::tenduke::ee::TendukeClient> createClientUsingAutodiscovery(
106 const ::tenduke::ee::ClientProperties &clientProperties,
107 const std::string &serviceUrl,
108 const P &authenticationConfiguration,
109 const std::string &initialStateAsJSON = {}
110 ) const
111 {
112 // Perform OIDC auto discovery
113 auto discoveryResult = services.oidcBackendConfiguration->discover(serviceUrl + "/.well-known/openid-configuration");
114 auto oidcConfiguration = services.oidcBackendConfiguration->toOIDCConfiguration(discoveryResult);
115 auto oauthConfiguration = mkOAuthConfiguration(*discoveryResult.getOAuthConfiguration(), authenticationConfiguration);
116
117 dumpAutodiscoveryResult(*services.oidcBackendConfiguration, discoveryResult);
118
119 return ::tenduke::ee::createClient(
120 services,
121 mkLicensingConfiguration(serviceUrl, clientProperties, *oidcConfiguration),
122 oauthConfiguration,
123 oidcConfiguration,
124 createOIDCLoginService(oauthConfiguration, oidcConfiguration, authenticationConfiguration),
125 authenticationConfiguration.oidcSessionConfiguration,
126 ::tenduke::ee::DeserializeStateFromJSON(services.jwtParser,services.jsonParser).from(initialStateAsJSON)
127 );
128 }
129
130protected:
138 virtual std::shared_ptr<::tenduke::oidc::OIDCLogin> createOIDCLoginService(
139 const std::shared_ptr<const ::tenduke::oauth::OAuthConfiguration> &oauthConfig,
140 const std::shared_ptr<const ::tenduke::oidc::OIDCConfiguration> &oidcConfig,
141 const P &authenticationConfig
142 ) const = 0;
143
150 virtual std::shared_ptr<::tenduke::oauth::OAuthConfiguration> mkOAuthConfiguration(
151 const ::tenduke::oauth::OAuthBackendConfiguration &oauthBackendConfig,
152 const P &authenticationConfig
153 ) const = 0;
154
163 virtual std::shared_ptr<::tenduke::ee::licensing::LicensingConfiguration> mkLicensingConfiguration(
164 const std::string &serviceUrl,
165 const ::tenduke::ee::ClientProperties &clientProperties,
166 const ::tenduke::oidc::OIDCConfiguration &oidcConfig
167 ) const
168 {
169 return std::make_shared<::tenduke::ee::licensing::LicensingConfiguration>(
170 serviceUrl + "/authz/",
171 clientProperties,
172 oidcConfig.verificationKey,
173 oidcConfig.digestAlgorithm
174 );
175 }
176
183 const ::tenduke::oidc::AutoDiscovery &service,
184 const ::tenduke::oidc::AutoDiscoveryResult &result
185 ) const
186 {
187 ::tenduke::log::debug("Auto discovered properties:");
188 ::tenduke::log::debug(" - authorization endpoint: " + result.getOAuthConfiguration()->authorizationEndpointUrl);
189 ::tenduke::log::debug(" - token endpoint: " + result.getOAuthConfiguration()->tokenEndpointUrl);
190 ::tenduke::log::debug(" - userinfo endpoint: " + result.getOOIDCConfiguration()->userinfoEndpoint);
191 ::tenduke::log::debug(" - issuer: " + result.getOOIDCConfiguration()->issuer);
192 ::tenduke::log::debug(" - verification key:");
193
194 auto jwk = service.getDefaultVerificationKey(result);
195
196 ::tenduke::log::debug(jwk->key->toPEM());
197 }
198
199protected:
201};
202
203
204}}
205
206
207#endif //TENDUKE_EE_BASECLIENTFACTORY_H
Configuration for supporting services.
Definition ServiceConfiguration.h:12
A "service locator" for core services used by Tenduke client.
Definition TendukeServices.h:26
const std::shared_ptr< const tenduke::json::JSONParser > jsonParser
JSON-parser.
Definition TendukeServices.h:72
const std::shared_ptr< const tenduke::jwt::JWTParserFactory > jwtParser
JWT-parser factory.
Definition TendukeServices.h:74
const std::shared_ptr< const tenduke::oidc::AutoDiscovery > oidcBackendConfiguration
OIDC configuration auto discovery service.
Definition TendukeServices.h:78
Class template for factories, which create 10Duke client.
Definition AbstractClientFactory.h:26
virtual std::shared_ptr<::tenduke::oidc::OIDCLogin > createOIDCLoginService(const std::shared_ptr< const ::tenduke::oauth::OAuthConfiguration > &oauthConfig, const std::shared_ptr< const ::tenduke::oidc::OIDCConfiguration > &oidcConfig, const P &authenticationConfig) const =0
Creates the authentication-specific OIDC login service.
std::unique_ptr<::tenduke::ee::TendukeClient > createClientUsingAutodiscovery(const ::tenduke::ee::ClientProperties &clientProperties, const std::string &serviceUrl, const P &authenticationConfiguration, const std::string &initialStateAsJSON={}) const
Creates client for 10Duke Enterprise, using OIDC autodiscovery for OAuth and OIDC parameters.
Definition AbstractClientFactory.h:105
AbstractClientFactory(const ::tenduke::TendukeServices &services)
Constructs new instance with given services.
Definition AbstractClientFactory.h:51
virtual std::unique_ptr<::tenduke::ee::TendukeClient > createClient(const ::tenduke::ee::ClientProperties &clientProperties, const std::string &serviceUrl, const ::tenduke::oauth::OAuthBackendConfiguration &oauthBackendConfiguration, const ::tenduke::oidc::OIDCConfiguration &oidcConfiguration, const P &authenticationConfiguration, const std::string &initialStateAsJSON={}) const
Creates client for 10Duke Enterprise from manually provided parameters.
Definition AbstractClientFactory.h:68
AbstractClientFactory(const std::string &clientId, const ::tenduke::ServiceConfiguration &serviceConfiguration=::tenduke::ServiceConfiguration())
Constructs new instance with default services.
Definition AbstractClientFactory.h:38
virtual std::shared_ptr<::tenduke::ee::licensing::LicensingConfiguration > mkLicensingConfiguration(const std::string &serviceUrl, const ::tenduke::ee::ClientProperties &clientProperties, const ::tenduke::oidc::OIDCConfiguration &oidcConfig) const
Creates licensing configuration from provided parameters.
Definition AbstractClientFactory.h:163
virtual std::shared_ptr<::tenduke::oauth::OAuthConfiguration > mkOAuthConfiguration(const ::tenduke::oauth::OAuthBackendConfiguration &oauthBackendConfig, const P &authenticationConfig) const =0
Creates full OAuth-configuration.
virtual void dumpAutodiscoveryResult(const ::tenduke::oidc::AutoDiscovery &service, const ::tenduke::oidc::AutoDiscoveryResult &result) const
Dumps OIDC autodiscovery result to log, using DEBUG log level.
Definition AbstractClientFactory.h:182
Service for deserializing client state from JSON.
Definition DeserializeStateFromJSON.h:17
::tenduke::ee::ClientState from(const std::string &stateSerializedAsJSON) const
Deserializes the state from JSON.
Definition DeserializeStateFromJSON.cpp:76
void debug(const char *message)
Write message to global logger at DEBUG-level.
Definition log.cpp:26
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4
tenduke::TendukeServices createDefaultTendukeServices(const std::string &clientId, const ::tenduke::ServiceConfiguration &serviceConfiguration=::tenduke::ServiceConfiguration())
Creates the default services used by Tenduke client.
Definition createDefaultTendukeServices.cpp:27