Call credentials can only be used on a secure channel.
In your example, it should look something like:
call_creds = grpc.metadata_call_credentials(UsernamePasswordCallCredential
s("foo"))
ssl_creds = grpc.ssl_channel_credentials()
channel_creds = grpc.composite_channel_credentials(ssl_creds, call_creds)
channel = grpc.secure_channel("localhost:50055", channel_creds)
Note that your server will need to host a secure port on localhost:50055
On Tue, Jan 10, 2017 at 6:31 PM, <[email protected]> wrote:
> Hi, I'm trying to attach CallCredentials to an RPC. This is what I've
> done, using AccessTokenCallCredentials as an example:
>
> class UsernamePasswordCallCredentials(grpc.AuthMetadataPlugin):
>
> def __init__(self, username):
>
> self._username = username
>
> def __call__(self, context, callback):
>
> print "in __call__"
>
> metadata = (('x-custom-auth-ticket', self._username),)
>
> callback(metadata, None)
>
>
>
> call_creds = metadata_call_credentials(UsernamePasswordCallCredential
> s("foo"))
>
> channel = grpc.insecure_channel("localhost:50055")
>
> stub = my_pb2_grpc.myStub(channel)
> stub.ListUser(Empty(), credentials=call_creds)
>
> Not only does my custom header not appear to be set, but I can't find an
> evidence that UsernamePasswordCallCredentials.__call__ is ever being
> called. Where am I going wrong?
>
> Thanks,
> Scott
>
> --
> 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/c5fd8d6d-f686-4e44-90e2-98e33fd8e75a%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/c5fd8d6d-f686-4e44-90e2-98e33fd8e75a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAGm2-Y7h1o9wx0vpRzZwJWCko7M%3D%3DpgmJ5o-%3DR9szMZWFnCL%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.