Restricting gRPC endpoints to authenticated users
gRPC is primarily designed for the backend; therefore, in most cases, it won't be possible to redirect to an SSO login. There simply won't be a UI that we will be able to do it from.
But because the OpenID Connect workflow obtains a token that is then stored in the application, we can simply reuse this token to get the user-facing application to authenticate into the gRPC application that it needs to communicate with. We will now demonstrate how to do this.
Setting up shared gRPC dependencies
We will start by creating a library that both the client and the server will share. As we did in the previous chapters, we will do so to ensure that both the client and the server use identical Protocol Buffers (Protobuf) definitions. Follow these next steps:
- Navigate to the
GrpcAuthentication
solution folder and execute the following command to create a class library project:dotnet new classlib -o GrpcDependencies
...