github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/Godeps/_workspace/src/google.golang.org/grpc/grpc-auth-support.md (about) 1 # Authentication 2 3 As outlined <a href="https://github.com/grpc/grpc/blob/master/doc/grpc-auth-support.md">here</a> gRPC supports a number of different mechanisms for asserting identity between an client and server. We'll present some code-samples here demonstrating how to provide TLS support encryption and identity assertions as well as passing OAuth2 tokens to services that support it. 4 5 # Enabling TLS on a gRPC client 6 7 ```Go 8 conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")) 9 ``` 10 11 # Enabling TLS on a gRPC server 12 13 ```Go 14 creds, err := credentials.NewServerTLSFromFile(certFile, keyFile) 15 if err != nil { 16 log.Fatalf("Failed to generate credentials %v", err) 17 } 18 lis, err := net.Listen("tcp", ":0") 19 server := grpc.NewServer(grpc.Creds(creds)) 20 ... 21 server.Serve(lis) 22 ``` 23 24 # Authenticating with Google 25 26 ## Google Compute Engine (GCE) 27 28 ```Go 29 conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""), grpc.WithPerRPCCredentials(oauth.NewComputeEngine()))) 30 ``` 31 32 ## JWT 33 34 ```Go 35 jwtCreds, err := oauth.NewServiceAccountFromFile(*serviceAccountKeyFile, *oauthScope) 36 if err != nil { 37 log.Fatalf("Failed to create JWT credentials: %v", err) 38 } 39 conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""), grpc.WithPerRPCCredentials(jwtCreds))) 40 ``` 41