我正在嘗試為 etcd v3+ 實(shí)現(xiàn) C# GRPC 客戶端。我能夠通過無身份驗證和通道 ssl 身份驗證進(jìn)行連接。但是,我也在嘗試找出基本的身份驗證機(jī)制。這是我的實(shí)現(xiàn)。using System;using System.Threading.Tasks;using System.Collections.Generic;using Grpc.Core;using Etcdserverpb;using Google.Protobuf;using System.Runtime.CompilerServices;using Grpc.Auth;using Grpc.Core.Interceptors;namespace myproj.etcd{ public class EtcdClient { Channel channel; KV.KVClient kvClient; string host; string username; string password; string authToken; Auth.AuthClient authClient; public EtcdClient(string host, string username, string password) { this.username = username; this.password = password; this.host = host; Authenticate(); // Expirementing with the token, trying to achieve my goal. channel = new Channel(host, ChannelCredentials.Create(ChannelCredentials.Insecure, GoogleGrpcCredentials.FromAccessToken(this.authToken))); // This works. //channel = new Channel(host, ChannelCredentials.Insecure); kvClient = new KV.KVClient(channel); } void Authenticate() { authClient = new Auth.AuthClient(new Channel(host,ChannelCredentials.Insecure)); var authRes = authClient.Authenticate(new AuthenticateRequest { Name = username, Password = password }); this.authToken = authRes.Token; }使用authenticate()方法,我能夠從 etcd 服務(wù)器獲取令牌,但無法找到在后續(xù)調(diào)用(Get、Put 等)中使用相同令牌的方法。
- 1 回答
- 0 關(guān)注
- 375 瀏覽
添加回答
舉報
0/150
提交
取消