iceberg-cpp
Loading...
Searching...
No Matches
oauth2_util.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 <string_view>
26#include <unordered_map>
27
31#include "iceberg/result.h"
32
35
36namespace iceberg::rest::auth {
37
39class ICEBERG_REST_EXPORT OAuth2Util {
40 public:
41 OAuth2Util() = delete;
42
51 const AuthProperties& properties);
52
57 static std::unordered_map<std::string, std::string> AuthHeaders(
58 const std::string& token);
59
74 HttpClient& client, AuthSession& session,
75 const std::unordered_map<std::string, std::string>& extra_headers,
76 const std::string& subject_token, const std::string& subject_token_type,
77 const std::optional<std::string>& actor_token,
78 const std::optional<std::string>& actor_token_type, const std::string& scope,
79 const std::string& oauth2_server_uri,
80 const std::unordered_map<std::string, std::string>& optional_params);
81
89 static std::optional<int64_t> ExpiresAtMillis(std::string_view token);
90
91 private:
92 static Result<std::unordered_map<std::string, std::string>> TokenExchangeRequest(
93 const std::string& subject_token, const std::string& subject_token_type,
94 const std::optional<std::string>& actor_token,
95 const std::optional<std::string>& actor_token_type, const std::string& scope,
96 const std::unordered_map<std::string, std::string>& optional_params);
97};
98
99} // namespace iceberg::rest::auth
HTTP client for making requests to Iceberg REST Catalog API.
Definition http_client.h:71
Authentication properties.
Definition auth_properties.h:37
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:48
OAuth2 token and authentication utilities.
Definition oauth2_util.h:39
static std::optional< int64_t > ExpiresAtMillis(std::string_view token)
Extract expiration time from a JWT token.
static Result< OAuthTokenResponse > FetchToken(HttpClient &client, AuthSession &session, const AuthProperties &properties)
Fetch an OAuth2 token using the client_credentials grant type.
static std::unordered_map< std::string, std::string > AuthHeaders(const std::string &token)
Build auth headers from a token string.
static Result< OAuthTokenResponse > ExchangeToken(HttpClient &client, AuthSession &session, const std::unordered_map< std::string, std::string > &extra_headers, const std::string &subject_token, const std::string &subject_token_type, const std::optional< std::string > &actor_token, const std::optional< std::string > &actor_token_type, const std::string &scope, const std::string &oauth2_server_uri, const std::unordered_map< std::string, std::string > &optional_params)
Exchange an OAuth2 token using the RFC 8693 grant type.
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.