iceberg-cpp
Loading...
Searching...
No Matches
auth_properties.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <optional>
24#include <string>
25#include <unordered_map>
26
28#include "iceberg/result.h"
29#include "iceberg/util/config.h"
30
33
34namespace iceberg::rest::auth {
35
37class ICEBERG_REST_EXPORT AuthProperties : public ConfigBase<AuthProperties> {
38 public:
39 template <typename T>
40 using Entry = const ConfigBase<AuthProperties>::Entry<T>;
41
42 // ---- Authentication type constants (not Entry-based) ----
43
44 inline static const std::string kAuthType = "rest.auth.type";
45 inline static const std::string kAuthTypeNone = "none";
46 inline static const std::string kAuthTypeBasic = "basic";
47 inline static const std::string kAuthTypeOAuth2 = "oauth2";
48 inline static const std::string kAuthTypeSigV4 = "sigv4";
49
50 // ---- Basic auth entries ----
51
52 inline static const std::string kBasicUsername = "rest.auth.basic.username";
53 inline static const std::string kBasicPassword = "rest.auth.basic.password";
54
55 // ---- SigV4 entries ----
56
59 inline static const std::string kSigV4Enabled = "rest.sigv4-enabled";
60 inline static const std::string kSigV4DelegateAuthType =
61 "rest.auth.sigv4.delegate-auth-type";
62
66 inline static const std::string kSigV4SigningRegion = "rest.signing-region";
67 inline static const std::string kSigV4SigningName = "rest.signing-name";
68 inline static const std::string kSigV4SigningNameDefault = "execute-api";
69 inline static const std::string kSigV4AccessKeyId = "rest.access-key-id";
70 inline static const std::string kSigV4SecretAccessKey = "rest.secret-access-key";
71 inline static const std::string kSigV4SessionToken = "rest.session-token";
72
73 // ---- OAuth2 entries ----
74
75 inline static Entry<std::string> kToken{"token", ""};
76 inline static Entry<std::string> kCredential{"credential", ""};
77 inline static Entry<std::string> kScope{"scope", "catalog"};
78 inline static Entry<std::string> kOAuth2ServerUri{"oauth2-server-uri",
79 "v1/oauth/tokens"};
80 inline static Entry<bool> kKeepRefreshed{"token-refresh-enabled", true};
81 inline static Entry<bool> kExchangeEnabled{"token-exchange-enabled", true};
82 inline static Entry<std::string> kAudience{"audience", ""};
83 inline static Entry<std::string> kResource{"resource", ""};
84
85 // ---- OAuth2 token type constants ----
86
87 inline static const std::string kAccessTokenType =
88 "urn:ietf:params:oauth:token-type:access_token";
89 inline static const std::string kRefreshTokenType =
90 "urn:ietf:params:oauth:token-type:refresh_token";
91 inline static const std::string kIdTokenType =
92 "urn:ietf:params:oauth:token-type:id_token";
93 inline static const std::string kSaml1TokenType =
94 "urn:ietf:params:oauth:token-type:saml1";
95 inline static const std::string kSaml2TokenType =
96 "urn:ietf:params:oauth:token-type:saml2";
97 inline static const std::string kJwtTokenType = "urn:ietf:params:oauth:token-type:jwt";
98
101 const std::unordered_map<std::string, std::string>& properties);
102
104 std::string token() const { return Get(kToken); }
106 std::string credential() const { return Get(kCredential); }
108 std::string scope() const { return Get(kScope); }
110 std::string oauth2_server_uri() const { return Get(kOAuth2ServerUri); }
112 bool keep_refreshed() const { return Get(kKeepRefreshed); }
114 bool exchange_enabled() const { return Get(kExchangeEnabled); }
115
117 const std::string& client_id() const { return client_id_; }
119 const std::string& client_secret() const { return client_secret_; }
120
122 std::unordered_map<std::string, std::string> optional_oauth_params() const;
123
124 private:
125 std::string client_id_;
126 std::string client_secret_;
127 std::string token_type_;
128 std::optional<int64_t> expires_at_millis_;
129};
130
131} // namespace iceberg::rest::auth
Definition config.h:73
Definition config.h:70
Authentication properties.
Definition auth_properties.h:37
std::unordered_map< std::string, std::string > optional_oauth_params() const
Build optional OAuth params (audience, resource) from config.
std::string credential() const
Get the raw credential string.
Definition auth_properties.h:106
std::string oauth2_server_uri() const
Get the token endpoint URI.
Definition auth_properties.h:110
bool exchange_enabled() const
Whether token exchange is enabled.
Definition auth_properties.h:114
const std::string & client_secret() const
Parsed client_secret from credential.
Definition auth_properties.h:119
std::string scope() const
Get the OAuth2 scope.
Definition auth_properties.h:108
std::string token() const
Get the bearer token.
Definition auth_properties.h:104
const std::string & client_id() const
Parsed client_id from credential (empty if no colon).
Definition auth_properties.h:117
static Result< AuthProperties > FromProperties(const std::unordered_map< std::string, std::string > &properties)
Build an AuthProperties from a properties map.
bool keep_refreshed() const
Whether token refresh is enabled.
Definition auth_properties.h:112
Provide typed configuration helpers.
Define symbol visibility macros for the REST catalog library.
REST catalog authentication APIs.
Definition auth_manager.h:34
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.