blob: 9817c7d8331a8ee21be86385f179cc7866b2bd15 [file]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_OAUTH_UTILS_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_OAUTH_UTILS_H_
#include <optional>
#include <string>
#include "redfish_v1.pb.h"
#include "config_parser.h"
#include "g3/grpc_headers.h"
namespace milotic::authz {
// Generates the subject of the OAuth token for the given peer.
std::string GenerateOAuthSubject(const PeerSpiffeIdentity& peer);
// Extracts the OAuth token from the Redfish request.
// Returns std::nullopt if the request doesn't contain an OAuth token.
std::optional<std::string> GetOAuthTokenFromRequest(
const ::redfish::v1::Request& request);
// Verifies the OAuth token regarding signature, subject, audience, issuer,
// and expiration, if it's valid, extract the Redfish role from the scope claim.
grpc::Status VerifyAndExtractRoleFromToken(const std::string& token,
const std::string& public_key,
const std::string& expected_subject,
const std::string& expected_audience,
const std::string& expected_issuer,
std::string& redfish_role);
} // namespace milotic::authz
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_OAUTH_UTILS_H_