Authentication
gRPC provides primitives for setting up TLS/SSL between clients and servers. It also provides the ability to setup mutual TLS between clients and servers! However, gRPC doesn’t provide the facility of authenticating users/services easily. It is up to the developer to implement their own authentication to verify services have provided the correct credentials on RPC’s. In this section we’re going to cover adding authentication to a gRPC service using metadata and JWT (JSON Web Tokens) to provide credentials to servers from clients.
Our clients will be providing a signed JWT using the metadata
field of all RPCs. The JWT will provide a username so the service can use it for any actions taken against it. Authentication is another great candidate to use gRPC interceptors, so that’s what we’re going to use to implement this functionality.
Let’s quickly build a simple Authentication
interceptor to our server that pulls the JWT out of the...