Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ std::string refreshClientCredAuth(ClientCredAuthParams& params) {
oss << "grant_type=" << encodedGrantType;
oss << "&client_id=" << encodedClientId;
oss << "&client_secret=" << encodedClientSecret;
oss << "&scope=" << encodedScope;
std::string tokenPost = oss.str();

// POST the creds and required data to exchange it for a token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void TokenCacheAuthProviderBase::refresh(
std::string accessToken =
this->obtainAccessToken(curl, responseData, responseHeaderData);

if (accessToken.empty()) {
throw std::runtime_error(
"Failed to obtain an access token from the identity provider");
}

// Cache the token
this->cacheToken(accessToken);

Expand Down
5 changes: 5 additions & 0 deletions src/trinoAPIWrapper/authProvider/tokens/tokenParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
#include "../../../util/delimKvpHelper.hpp"
#include "../../../util/stringSplitAndTrim.hpp"
#include "../../../util/timeUtils.hpp"
#include "../../../util/writeLog.hpp"

json parseAccessToken(std::string& accessToken) {
// NOTE: There is no need to validate the token here, because it's
// generated by Trino controller, which does its own authentication
// to the identity provider that includes validating the token signature.
// If this driver got a token from the Trino controller, we can just use it.
std::vector<std::string> jwtComponents = stringSplitAndTrim(accessToken, '.');
if (jwtComponents.size() < 2) {
WriteLog(LL_ERROR, " ERROR: Access token is not a well-formed JWT");
return json(json::value_t::object);
}
std::string jwtPayloadEncoded = jwtComponents[1];
std::string jwtPayloadDecoded = fromBase64url(jwtPayloadEncoded);
json jwtPayload = json::parse(jwtPayloadDecoded);
Expand Down