Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
Configuration.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Auth_OAuth_Configuration_h_
5#define _Stroika_Frameworks_Auth_OAuth_Configuration_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Common/Common.h"
11#include "Stroika/Foundation/Common/GUID.h"
12#include "Stroika/Foundation/Containers/KeyedCollection.h"
13#include "Stroika/Foundation/Containers/Sequence.h"
14#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
16
17/**
18 * \file
19 *
20 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
21 */
22
23namespace Stroika::Frameworks::Auth::OAuth {
24
25 using namespace Stroika::Foundation;
26
30 using Containers::Set;
31 using IO::Network::URI;
32
34
35 /**
36 * Documentation about these concepts:
37 * google - https://developers.google.com/identity/protocols/oauth2/web-server#httprest
38 * - https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow
39 */
40
41 /**
42 * Documentation where to get/register application IDs
43 * google - https://console.cloud.google.com/apis/credentials
44 * azure - https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade
45 * - https://learn.microsoft.com/en-us/azure/active-directory-b2c/client-credentials-grant-flow?pivots=b2c-user-flow#app-registration-overview
46 */
47
48 /**
49 * \brief sometimes called ClientID, and sometimes called applicationID
50 *
51 * \note though this is often a GUID, it cannot be assumed to be a GUID (google for example, doesn't use GUIDs).
52 */
54
55 /**
56 * often require things like no #/fragments
57 */
59
60 /**
61 * \brief Track configuration data about stuff that differentiates different
62 * OAuth providers - what URLs to use, base url, relative off that URLs for login/upgrade token/refresh etc.
63 * ALL very prelim at this stage.
64 *
65 * see javascript frameworks - for doing auth2 - convert token to access token etc...
66 * stuff to fetch 'keys' like I vaguely remember from openid... to validate JWTs...\
67 *
68 *
69 *
70 * @todo - create API structure so can fill in details on this via fetch of https://accounts.google.com/.well-known/openid-configuration
71 * read docs on that - and meaning of various parts - and list here etc...
72 *
73 * probably use more optional<URI> on these....
74 */
76 public:
77 /**
78 * name used to join between ProviderConfiguration and ClientConfiguration::fProvider
79 */
81
82 /**
83 * EG https://accounts.google.com/.well-known/openid-configuration
84 * https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
85 * https://account.apple.com/.well-known/openid-configuration
86 * https://www.facebook.com/.well-known/openid-configuration
87 * https://dev-84941762.okta.com/.well-known/openid-configuration?client_id=0oa5km1v306LXN57y5d7
88 *
89 * \see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
90 * \see https://openid.net/specs/openid-connect-rpinitiated-1_0.html
91 *
92 * \note - this ID may or may not end in '/.well-known/openid-configuration'; however, even if it
93 * doesn't, that is implicitly appended before fetching the configuration data.
94 */
96
97 /**
98 * Same as authorization_endpoint from openid_configuration_uri
99 */
100 optional<URI> auth_uri;
101
102 /**
103 * Same as token_endpoint from openid_configuration_uri
104 * \note facebook doesn't appear to support this - so I guess just use id_token and (what flow)???
105 */
106 optional<URI> token_uri;
107
108 /**
109 * if missing, try FetchAdditionsFromOpenIDConfigurationURI (), or hopefully get id_token from GetToken() api.
110 */
111 optional<URI> userinfo_endpoint;
112
113 /**
114 * GOOGLE uses this but I cannot find docs - https://accounts.google.com/.well-known/openid-configuration
115 */
116 optional<URI> revocation_endpoint;
117
118 /**
119 * Same as jwks_uri from openid_configuration_uri
120 */
122
123 /**
124 * @brief RFC 7662 compatible API for finding info about a token - https://datatracker.ietf.org/doc/html/rfc7662
125 */
127
128 /**
129 * @brief logically similar to introspection_endpoint, but googles incompatible way
130 */
131 optional<URI> tokeninfo_endpoint;
132
133 /**
134 * Fetch the data from the openid_configuration_uri, and use it to augment the fields
135 * of this structure, and return the updated record (replacing items that conflict).
136 *
137 * This can be used to fill in a Provider configuration when all you have is the URL for openid-configuration
138 *
139 * \par Example Usage
140 * \code
141 * ProviderConfiguration providerConfig =
142 * ProviderConfiguration{.name = "MyOKTAAccount", .openid_configuration_uri = "https://dev-84941762.okta.com/.well-known/openid-configuration?client_id=0oa5km1v306LXN57y5d7"}
143 * .FetchAdditionsFromOpenIDConfigurationURI ();
144 * \endcode
145 */
147
148 /**
149 */
150 nonvirtual bool operator== (const ProviderConfiguration& rhs) const = default;
151
152#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
153 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
154#endif
155 /**
156 */
157 nonvirtual auto operator<=> (const ProviderConfiguration& rhs) const = default;
158
159#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
160 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
161#endif
162
163 static const ObjectVariantMapper kMapper;
164
165 nonvirtual String ToString () const;
166 };
167
168 namespace Private_ {
169 // NOTE - cannot do this due to ODR violation
170 // using My_Extractor_ = decltype ([] (const ProviderConfiguration& t) -> String { return t.name; });
171 struct My_Extractor_ {
172 String operator() (const ProviderConfiguration& t) const noexcept
173 {
174 return t.name;
175 }
176 };
178 }
179 /**
180 * A list of definitions for configurations.
181 *
182 * @todo provide predefined one inside this framework, and allow it to be updated/revised in applications.
183 * REFERENED IMPLICITLY in ClientConfiguration
184 */
186
187 /**
188 * a predefined set of configurations, but you may need to update/roll your own, as this could get out of date.
189 */
191
192 /**
193 * \note logically, we want to aggregate ProviderConfiguration inside ClientConfiguration, but
194 * since it can generally be static and unchanged, we keep it separate, and just link up/reference by 'name'
195 */
197 String fProvider; // refers to some element of ProvidersConfigurationType
198
199 /**
200 * This value is sometimes referred to in OAUTH as ClientID
201 */
203
204 /**
205 * List of acceptable redirect URLs allowed in (which flows) authorization_code acquisition; only one will be actually used
206 * in the authentication_code request.
207 */
209
210 /**
211 * List of acceptable scopes requested. Some subset (often all) will be requested at in the authentication_code request.
212 */
214
215 /**
216 * This is used in some places, and must be hidden in others (so optional).
217 */
218 optional<String> fClientSecret;
219
220 static const ObjectVariantMapper kMapper;
221
222 /**
223 */
224 nonvirtual bool operator== (const ClientConfiguration& rhs) const = default;
225
226 /**
227 */
228 nonvirtual auto operator<=> (const ClientConfiguration& rhs) const;
229
230 /**
231 */
232 nonvirtual String ToString () const;
233 };
234
235 /**
236 * \par Example Usage
237 * \code
238 * {
239 * { .fProvider = "google", .fApplicationID = "003...", .fRedirectURLs = ["http://localhost"], .fScopes = ["openid"] },
240 * { .fProvider = "apple", .fApplicationID = "003...", .fRedirectURLs = ["http://localhost"], .fScopes = ["openid"] },
241 * { .fProvider = "twitter", .fApplicationID = "003...", .fRedirectURLs = ["http://localhost"], .fScopes = ["openid"] },
242 * { .fProvider = "facebook", .fApplicationID = "003...", .fRedirectURLs = ["http://localhost"], .fScopes = ["openid"] },
243 * }
244 * \endcode
245 */
247
248}
249
250/*
251 ********************************************************************************
252 ***************************** Implementation Details ***************************
253 ********************************************************************************
254 */
255#include "Configuration.inl"
256
257#endif /*_Stroika_Frameworks_Auth_OAuth_Configuration_h_*/
const ProvidersConfigurations kDefaultProviderConfigurations
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
a cross between Mapping<KEY, T> and Collection<T> and Set<T>
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
Track configuration data about stuff that differentiates different OAuth providers - what URLs to use...
nonvirtual ProviderConfiguration FetchAdditionsFromOpenIDConfigurationURI() const
optional< URI > tokeninfo_endpoint
logically similar to introspection_endpoint, but googles incompatible way
optional< URI > introspection_endpoint
RFC 7662 compatible API for finding info about a token - https://datatracker.ietf....