gRPCClient.jl icon indicating copy to clipboard operation
gRPCClient.jl copied to clipboard

Adding auth token to grpc headers

Open innuo opened this issue 1 year ago • 0 comments

I need to add an auth token (and other metadata ) to the gprc headers, and update it regularly when they expire. What is the recommended way to do that? I would appreciate any help.

Here is what I have been doing, but it sometimes causes segmentation faults when I do multiple sends asynchronously.

using gRPCClient
function update_headers(; meta_bool=false)

          LibCURL.curl_slist_free_all(gRPCClient.GRPC_STATIC_HEADERS[]) #free previous slist
          headers = C_NULL
          headers = LibCURL.curl_slist_append(headers, "Content-Type: application/grpc+proto")
          headers = LibCURL.curl_slist_append(headers, "Content-Length:")
          headers = LibCURL.curl_slist_append(headers, "te: trailers")
        
          token = get_access_token()
          headers = LibCURL.curl_slist_append(headers, "rpc-auth-header: $token")
        
          if meta_bool
              headers = LibCURL.curl_slist_append(headers, "meta_bool: $(meta_bool)")
          end
        
          gRPCClient.GRPC_STATIC_HEADERS[] = headers
          return nothing

 end

innuo avatar Mar 12 '24 18:03 innuo