iceberg-cpp
Loading...
Searching...
No Matches
auth_session.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 <memory>
23#include <optional>
24#include <string>
25#include <unordered_map>
26
30#include "iceberg/result.h"
31
34
35namespace iceberg::rest::auth {
36
38struct ICEBERG_REST_EXPORT OAuth2SessionInfo {
39 std::string token;
40 std::string issued_token_type;
41 std::string credential;
42 std::string scope;
43 std::string oauth2_server_uri;
44 std::unordered_map<std::string, std::string> optional_oauth_params;
45};
46
48class ICEBERG_REST_EXPORT AuthSession {
49 public:
50 virtual ~AuthSession() = default;
51
67
69 virtual std::optional<OAuth2SessionInfo> OAuth2Info() const { return std::nullopt; }
70
78 virtual Status Close() { return {}; }
79
88 static std::shared_ptr<AuthSession> MakeDefault(
89 std::unordered_map<std::string, std::string> headers);
90
109 const OAuthTokenResponse& initial_token, const std::string& token_endpoint,
110 const std::string& client_id, const std::string& client_secret,
111 const std::string& scope, bool keep_refreshed,
112 const std::unordered_map<std::string, std::string>& optional_oauth_params,
113 std::shared_ptr<HttpClient> client);
114};
115
116} // namespace iceberg::rest::auth
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:48
virtual Result< HttpRequest > Authenticate(HttpRequest request)=0
Authenticate an outgoing HTTP request.
static std::shared_ptr< AuthSession > MakeDefault(std::unordered_map< std::string, std::string > headers)
Create a session with static headers.
virtual std::optional< OAuth2SessionInfo > OAuth2Info() const
Return OAuth2 metadata when this is an OAuth2 session.
Definition auth_session.h:69
static Result< std::shared_ptr< AuthSession > > MakeOAuth2(const OAuthTokenResponse &initial_token, const std::string &token_endpoint, const std::string &client_id, const std::string &client_secret, const std::string &scope, bool keep_refreshed, const std::unordered_map< std::string, std::string > &optional_oauth_params, std::shared_ptr< HttpClient > client)
Create an OAuth2 session with automatic token refresh.
virtual Status Close()
Close the session and release any resources.
Definition auth_session.h:78
Define REST HTTP request types.
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.
An outgoing HTTP request. Mirrors Java's HttpRequest so signing implementations like SigV4 see method...
Definition http_request.h:89
Response from an OAuth2 token endpoint.
Definition types.h:300
OAuth2 metadata used to derive child authentication sessions.
Definition auth_session.h:38