10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
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 ROPG, // Resource Owner Password Credentials Grant https://datatracker.ietf.org/doc/html/rfc6749#section-4.3
27 CCG // Client Credentials Grant https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
28 };
29
30public:
39 std::string clientId,
40 std::string clientSecret,
41 std::string redirectURI,
42 const enum OAuthFlow flow
43 ) : clientId(std::move(clientId))
44 , clientSecret(std::move(clientSecret))
45 , redirectURI(std::move(redirectURI))
46 , flow(flow)
47 {}
48
50 const std::string clientId;
52 const std::string clientSecret;
54 const std::string redirectURI;
55
57 const enum OAuthFlow flow;
58
59public:
65 static std::string flowToString(const enum OAuthFlow flow)
66 {
67 switch(flow)
68 {
69 case PKCE: return "PKCE";
70 case DEVICE: return "DEVICE";
71 default: return "UNKNOWN";
72 }
73 }
74
80 static enum OAuthFlow stringToFlow(const std::string &string)
81 {
82 if ("DEVICE" == string) {
83 return OAuthFlow::DEVICE;
84 }
85 if ("PKCE" == string) {
86 return OAuthFlow::PKCE;
87 }
88 return OAuthFlow::UNKNOWN;
89 }
90
91public:
95 class Builder {
96 public:
101 explicit Builder(const OAuthFlow flow) : oauthFlow(flow) {}
102
108 Builder &clientId(const std::string &pClientId)
109 {
110 this->oauthClientId = pClientId;
111 return *this;
112 }
113
119 Builder &redirectURI(const std::string &pRedirectURI)
120 {
121 this->oauthRedirectURI = pRedirectURI;
122 return *this;
123 }
124
130 Builder &clientSecret(const std::string &pClientSecret)
131 {
132 this->oauthClientSecret = pClientSecret;
133 return *this;
134 }
135
141 {
143 oauthClientId,
144 oauthClientSecret,
145 oauthRedirectURI,
146 oauthFlow
147 );
148 }
149
150 private:
152 std::string oauthClientId;
154 std::string oauthClientSecret;
156 std::string oauthRedirectURI;
158 const enum OAuthFlow oauthFlow;
159 };
160
166 {
167 return Builder(OAuthFlow::PKCE);
168 }
169};
170
171
172}}
173
174#endif // TENDUKE_OAUTH_OAUTHCLIENTCONFIGURATION_H
Builder for the configuration.
Definition OAuthClientConfiguration.h:95
Builder & clientSecret(const std::string &pClientSecret)
Fluently sets client secret.
Definition OAuthClientConfiguration.h:130
Builder & clientId(const std::string &pClientId)
Fluent sets the OAuth client id.
Definition OAuthClientConfiguration.h:108
Builder(const OAuthFlow flow)
Constructs new instance.
Definition OAuthClientConfiguration.h:101
OAuthClientConfiguration build()
Builds the configuration.
Definition OAuthClientConfiguration.h:140
Builder & redirectURI(const std::string &pRedirectURI)
Fluently sets redirect URI.
Definition OAuthClientConfiguration.h:119
Container for OAuth-client-configuration.
Definition OAuthClientConfiguration.h:17
enum OAuthFlow flow
The flow.
Definition OAuthClientConfiguration.h:57
const std::string clientSecret
(Optional) OAuth 2 client secret, configured also in the server.
Definition OAuthClientConfiguration.h:52
static Builder forPKCEFlow()
Starts building configuration for PKCE-flow.
Definition OAuthClientConfiguration.h:165
const std::string clientId
OAuth 2 client id, configured also in the server.
Definition OAuthClientConfiguration.h:50
const std::string redirectURI
OAuth2 redirect-URI for browser-based based authentication.
Definition OAuthClientConfiguration.h:54
OAuthClientConfiguration(std::string clientId, std::string clientSecret, std::string redirectURI, const enum OAuthFlow flow)
Constructs new instance.
Definition OAuthClientConfiguration.h:38
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:65
static enum OAuthFlow stringToFlow(const std::string &string)
Parses string representation of a flow.
Definition OAuthClientConfiguration.h:80
OAuth services.
Definition AccessTokenRequestAuthenticator.h:8
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4