userver: samples/grpc_middleware_service/src/middlewares/server/middleware.cpp
Loading...
Searching...
No Matches
samples/grpc_middleware_service/src/middlewares/server/middleware.cpp
#include "middleware.hpp"
#include <middlewares/auth.hpp>
namespace sample::grpc::auth::server {
Middleware::Middleware() = default;
void Middleware::Handle(ugrpc::server::MiddlewareCallContext& context) const {
const auto& metadata = context.GetCall().GetContext().client_metadata();
auto it = metadata.find(kKey);
if (it == metadata.cend() || it->second != kCredentials) {
auto& rpc = context.GetCall();
rpc.FinishWithError(::grpc::Status{::grpc::StatusCode::PERMISSION_DENIED, "Invalid credentials"});
LOG_ERROR() << "Invalid credentials";
return;
}
context.Next();
}
} // namespace sample::grpc::auth::server