2020#include " iceberg/catalog/rest/auth/auth_managers.h"
2121
2222#include < algorithm>
23+ #include < cctype>
2324
2425#include " iceberg/catalog/rest/auth/auth_properties.h"
2526
@@ -30,29 +31,30 @@ namespace {
3031// / \brief Convert a string to lowercase for case-insensitive comparison.
3132std::string ToLower (std::string_view str) {
3233 std::string result (str);
33- std::transform (result. begin (), result. end () , result.begin (),
34- [](unsigned char c) { return std::tolower (c); });
34+ std::ranges:: transform (result, result.begin (),
35+ [](unsigned char c) { return std::tolower (c); });
3536 return result;
3637}
3738
3839// / \brief Infer the authentication type from properties.
3940// /
4041// / If no explicit auth type is set, this function tries to infer it from
41- // / other properties. For example, if "credential" or "token" is present,
42- // / it implies OAuth2 authentication.
42+ // / other properties. If "credential" or "token" is present, it implies
43+ // / OAuth2 authentication. Otherwise, defaults to no authentication.
44+ // /
45+ // / This behavior is consistent with Java Iceberg's AuthManagers.
4346std::string InferAuthType (
4447 const std::unordered_map<std::string, std::string>& properties) {
45- // Check for explicit auth type
48+ // Check for explicit auth type first
4649 auto it = properties.find (std::string (AuthProperties::kAuthType ));
4750 if (it != properties.end () && !it->second .empty ()) {
4851 return ToLower (it->second );
4952 }
5053
51- // Infer from OAuth2 properties
54+ // Infer from OAuth2 properties (credential or token)
5255 bool has_credential =
5356 properties.contains (std::string (AuthProperties::kOAuth2Credential ));
5457 bool has_token = properties.contains (std::string (AuthProperties::kOAuth2Token ));
55-
5658 if (has_credential || has_token) {
5759 return std::string (AuthProperties::kAuthTypeOAuth2 );
5860 }
0 commit comments