Closed tbillington closed 7 years ago
It is easy to implement call metadata, but I'm not sure what API should look like.
Then how can one do authentication with tokens? https://github.com/grpc/grpc-go/issues/106#issuecomment-77680241
E.g. with HTTP Auth, the client sends username+password, gets a token (signed user_id), and sends that with every request from then on. I found some info about how to do that with gRPC and they suggest using Metadata for that: https://groups.google.com/d/msg/grpc-io/LP94S3UF8bU/tWCm0ZA_FwAJ
Is it still possible with this lib right now, even though it doesn't support Metadata yet?
Or is there support for the second solution mentioned here? https://groups.google.com/d/msg/grpc-io/iLHgWC8o8UM/2PN4WaA9anMJ
I'm working on gRPC metadata currently.
AFAIU, gRPC metadata is a fancy name for request/response custom HTTP headers.
So, I decided (if you have ideas how to do it better, please share) that for method
rpc SayHello (HelloRequest) returns (HelloReply) {}
this code is generated:
fn SayHello(&self, o: GrpcRequestOptions, req: HelloRequest)
-> GrpcSingleResponse<HelloReply> { ... }
GrpcRequestOptions
contains metadata
field where you can store whichever headers you want, and GrpcSingleResponse
is basically an alias for Future<(Metadata, Future<Reply>)>
.
@stepancheg I'm not an expert on gRPC, but there are some experts in #grpc on Freenode. They helped me with some questions (about using grpc from js), I think it would be helpful to ask them what the best way would be to expose the metadata functionality.
OK, initial metadata is implemented in master, trailing metadata not yet.
Thanks!
I installed the grpc-compiler
from github, but how can I now get the metadata of a request on the server side, and construct metadata for the reponse?
The entries
field of GrpcMetadata
is private and I don't see any accessors:
https://github.com/stepancheg/grpc-rust/blob/master/src/metadata.rs#L71
Also I don't see a way to construct GrpcMetadata (other than from_headers()
)..
Btw, if I want to respond to a login request with a session token (like a cookie), I should use completed_with_metadata()
, right?
The entries field of GrpcMetadata is private and I don't see any accessors
I made fields public now, but there should be better API to access metadata.
Btw, if I want to respond to a login request with a session token (like a cookie), I should use completed_with_metadata(), right?
Yes, if your call is synchronous, or GrpcSingleResponse::new
or another variable if it is asynchronous.
It was mentioned in https://github.com/grpc/grpc/issues/9316 that it's not supported, just curious about the status now.