10Duke Scale C++ Client
All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
OAuthClientConfiguration.h
1#ifndef TENDUKE_OAUTH_OAUTHCLIENTCONFIGURATION_H
2#define TENDUKE_OAUTH_OAUTHCLIENTCONFIGURATION_H
3
4#include "crypto/PublicKey.h"
5
6#include <memory>
7#include <string>
8
9namespace tenduke { namespace oauth {
10
11
17{
18public:
22 {
23 UNKNOWN,
24 PKCE, // https://datatracker.ietf.org/doc/html/rfc7636
25 DEVICE // https://datatracker.ietf.org/doc/html/rfc8628
26 };
27
28public:
37 std::string clientId,
38 std::string clientSecret,
39 std::string redirectURI,
40 const enum OAuthFlow flow
41 ) : clientId(std::move(clientId))
42 , clientSecret(std::move(clientSecret))
43 , redirectURI(std::move(redirectURI))
44 , flow(flow)
45 {}
46
48 const std::string clientId;
50 const std::string clientSecret;
52 const std::string redirectURI;
53
55 const enum OAuthFlow flow;
56
57public:
63 static std::string flowToString(const enum OAuthFlow flow)
64 {
65 switch(flow)
66 {
67 case PKCE: return "PKCE";
68 case DEVICE: return "DEVICE";
69 default: return "UNKNOWN";
70 }
71 }
72
78 static enum OAuthFlow stringToFlow(const std::string &string)
79 {
80 if ("DEVICE" == string) {
81 return OAuthFlow::DEVICE;
82 }
83 if ("PKCE" == string) {
84 return OAuthFlow::PKCE;
85 }
86 return OAuthFlow::UNKNOWN;
87 }
88
89public:
93 class Builder {
94 public:
99 explicit Builder(const OAuthFlow flow) : oauthFlow(flow) {}
100
106 Builder &clientId(const std::string &pClientId)
107 {
108 this->oauthClientId = pClientId;
109 return *this;
110 }
111
117 Builder &redirectURI(const std::string &pRedirectURI)
118 {
119 this->oauthRedirectURI = pRedirectURI;
120 return *this;
121 }
122
128 Builder &clientSecret(const std::string &pClientSecret)
129 {
130 this->oauthClientSecret = pClientSecret;
131 return *this;
132 }
133
139 {
141 oauthClientId,
142 oauthClientSecret,
143 oauthRedirectURI,
144 oauthFlow
145 );
146 }
147
148 private:
150 std::string oauthClientId;
152 std::string oauthClientSecret;
154 std::string oauthRedirectURI;
156 const enum OAuthFlow oauthFlow;
157 };
158
164 {
165 return Builder(OAuthFlow::PKCE);
166 }
167};
168
169
170}}
171
172#endif // TENDUKE_OAUTH_OAUTHCLIENTCONFIGURATION_H
Builder for the configuration.
Definition OAuthClientConfiguration.h:93
Builder & clientSecret(const std::string &pClientSecret)
Fluently sets client secret.
Definition OAuthClientConfiguration.h:128
Builder & clientId(const std::string &pClientId)
Fluent sets the OAuth client id.
Definition OAuthClientConfiguration.h:106
Builder(const OAuthFlow flow)
Constructs new instance.
Definition OAuthClientConfiguration.h:99
OAuthClientConfiguration build()
Builds the configuration.
Definition OAuthClientConfiguration.h:138
Builder & redirectURI(const std::string &pRedirectURI)
Fluently sets redirect URI.
Definition OAuthClientConfiguration.h:117
Container for OAuth-client-configuration.
Definition OAuthClientConfiguration.h:17
enum OAuthFlow flow
The flow.
Definition OAuthClientConfiguration.h:55
const std::string clientSecret
(Optional) OAuth 2 client secret, configured also in the server.
Definition OAuthClientConfiguration.h:50
static Builder forPKCEFlow()
Starts building configuration for PKCE-flow.
Definition OAuthClientConfiguration.h:163
const std::string clientId
OAuth 2 client id, configured also in the server.
Definition OAuthClientConfiguration.h:48
const std::string redirectURI
OAuth2 redirect-URI for browser-based based authentication.
Definition OAuthClientConfiguration.h:52
OAuthClientConfiguration(std::string clientId, std::string clientSecret, std::string redirectURI, const enum OAuthFlow flow)
Constructs new instance.
Definition OAuthClientConfiguration.h:36
OAuthFlow
Type of the OAuth flow.
Definition OAuthClientConfiguration.h:22
static std::string flowToString(const enum OAuthFlow flow)
Converts the flow to a string representation.
Definition OAuthClientConfiguration.h:63
static enum OAuthFlow stringToFlow(const std::string &string)
Parses string representation of a flow.
Definition OAuthClientConfiguration.h:78
OAuth services.
Definition AccessTokenRequestAuthenticator.h:8
Root for classes, functions and globals of 10Duke C++ Client.
Definition BackendConfiguration.h:7