I was able to get this working by simply calling AddMetadata on the client context to set the authorization header. This appears to work for both secure and insecure connections, so I'll go with this approach rather than using the custom authenticator.
On Wednesday, 7 February 2018 12:20:11 UTC-8, [email protected] wrote: > > I'm looking into how to support client connections to disparate services > using custom oAuth2 tokens. The services may or may not support SSL/TLS. > > I have created a custom authenticator plugin following the sample code at > https://grpc.io/docs/guides/auth.html. > > I build my custom call credentials and store them using a > CompositeChannelCredientials object > > auto call_creds = > grpc::MetadataCredentialsFromPlugin(std::unique_ptr<grpc::MetadataCredentialsPlugin>(new > > MyCustomAuthenticator(accessToken))); > > if (secure) > mCredentials = > grpc::CompositeChannelCredentials(grpc::SslCredentials(opts), call_creds); > else > mCredentials = > grpc::CompositeChannelCredentials(grpc::InsecureChannelCredentials(), > call_creds); > > However, I noticed during debugging that mCredentials is nullptr when > connecting to a service that doesn't support SSL/TLS. It looks like > CompositeChannelCredentials attempts to cast the InsecureChannelCredentials > to SecureChannelCredentials, with this cast returning NULL. > > Is there any documentation or sample code of how to make an authenticated > call over an insecure channel? Is this something that's currently supported > in the C++ API? > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/ef391109-95d8-4a1b-af5f-b0d5b46e4207%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
