What's the equivalent of grpc.WithPerRPCCredentials in C++?

74 views
Skip to first unread message

Martin Dørum

unread,
Sep 12, 2022, 6:54:04 AM9/12/22
to grpc.io


We have some Go code which uses JWT as per RPC credentials with gRPC. I'm trying to implement a client in C++, but I can't figure out what the equivalent of the grpc.WithPerRPCCredentials dial option is in C++. The Go code is like this:

type claims struct {
    claims map[string]string
    secure bool
}

func (c claims) GetRequestMetadata(ctx context.Context, a ...string) (map[string]string, error) {
    return c.claims, nil
}

func (c claims) RequireTransportSecurity() bool {
    return c.secure
}

fn connect() {
    clms := claims{
        claims: make(map[string]string),
        secure: !c.insecure,
    }
    clms.claims["token"] = ourJWT;
    conn, err := grpc.DialContext(context.Background(), addr, grpc.WithPerRPCCredentials(clms))
}


What's the equivalent way in C++ to create credentials which attaches a JWT to each request?

Easwar Swaminathan

unread,
Sep 14, 2022, 1:58:08 PM9/14/22
to grpc.io
These are called CallCredentials in C++. See: https://github.com/grpc/grpc/blob/master/include/grpcpp/security/credentials.h#L128-L153

And this might be what you are looking for, to attach JWT to every request: https://github.com/grpc/grpc/blob/master/src/cpp/client/secure_credentials.cc#L332
Reply all
Reply to author
Forward
0 new messages