static void Main(string[] args) { try { // Only needed to override validation for servers with self-signed certificates EnsureCertificateValidation(); // Login to server Console.WriteLine("Authenticating..."); Auth.AuthClient AC = new Auth.AuthClient(); if (!AC.LogOnWithPassword("admin", "foobar")) { Console.WriteLine("Failed to login!"); Environment.Exit(1); } // Make PublicAPI calls Console.WriteLine("Making ListRecorders call..."); RemoteRecorderManagement.RemoteRecorderManagementClient RMC = new RemoteRecorderManagement.RemoteRecorderManagementClient(); RemoteRecorderManagement.ListRecordersResponse RR = RMC.ListRecorders(null, new RemoteRecorderManagement.Pagination() { MaxNumberResults = 255 }, RemoteRecorderManagement.RecorderSortField.Name); Console.WriteLine("Made ListRecorders call"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Measure.MeasureClient(channel); var authClient = new Auth.AuthClient(channel); var tokenReply = authClient.GetToken(new TokenRequest() { Name = "Coding4FunClient" }); var headers = new Metadata(); headers.Add("Authorization", $"Bearer {tokenReply.Token}"); using (var call = client.SendMeasure(headers)) { for (var i = 0; i < 5; i++) { var measure = new MeasureRequest() { Name = "Temp", Value = Random.Next() }; await call.RequestStream.WriteAsync(measure); Console.WriteLine($"Measure send {measure.Value}"); await Task.Delay(2000); } await call.RequestStream.CompleteAsync(); await call; } }
public RealDataProvider() { _channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); _authClient = new Auth.AuthClient(_channel); _projectsClient = new Projects.ProjectsClient(_channel); _tasksClient = new Tasks.TasksClient(_channel); _usersClient = new Users.UsersClient(_channel); }
/** * get token from etcd with name and password. * * @param channel channel to etcd * @param username auth name * @param password auth password * @return authResp */ private static AuthenticateResponse Authenticate(Channel channel, ByteSequence username, ByteSequence password) { AuthenticateRequest requet = new AuthenticateRequest(); requet.Name = username.ToString(); requet.Password = password.ToString(); Auth.AuthClient authClient = new Auth.AuthClient(channel); var rsp = authClient.Authenticate(requet); AuthenticateResponse response = new AuthenticateResponse(rsp); return(response); }
private static async Task Main(string[] args) { GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:45679"); var httpsClientTicker = new Ticker.TickerClient(channel); GrpcChannel authChannel = GrpcChannel.ForAddress("https://localhost:56790"); var httpsClient = new Auth.AuthClient(authChannel); var interceptorHttps = channel.Intercept(new HeaderLoggerInterceptor()); var healthChecker = new Health.HealthClient(interceptorHttps); string serviceName = "Ticker"; var result = await healthChecker.CheckAsync(new HealthCheckRequest { Service = serviceName }); Console.WriteLine(result?.Status); /* var reply = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" }); * var replyUser = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" }); * * var tokenAdmin = * await Authenticate(reply.Role); * * var tokenUser = await Authenticate(replyUser.Role); * * * Console.WriteLine(tokenAdmin); * Console.WriteLine(tokenUser); * * await ClientStreaming(httpsClientTicker, 1, tokenUser); * * * * /*await UpdateTickHandling(httpsClient, * new TickToAdd * { * InstrumentId = 1, * Close = (DecimalValue)5.6234m, * Open = (DecimalValue)5.6225m, * High = (DecimalValue)5.6238m, * Low = (DecimalValue)5.6224m, * Symbol = 2 * }); * await GetTicksForQuota(httpsClient, 1);*/ //await ClientStreaming(httpsClient, 1); Console.WriteLine("Press any key to close app..."); Console.ReadLine(); }
/// <summary> /// Used to authenticate etcd server through basic auth /// </summary> private void Authenticate() { _authClient = new Auth.AuthClient(_channel); AuthenticateResponse authRes = _authClient.Authenticate(new AuthenticateRequest { Name = _username, Password = _password }); _authToken = authRes.Token; _headers = new Metadata { { "Authorization", _authToken } }; }
public async Task <LogoutResponse> Logout([Required] LogoutRequest request) { if (!ModelState.IsValid) { throw new Exception("Invalid model"); } var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel => { var client = new Auth.AuthClient(channel); _logger.LogDebug("Grpc auth logout {@request}", request); return(await client.LogoutAsync(request)); }); return(response); }
/// <summary> /// Used to authenticate etcd server through basic auth /// </summary> private void Authenticate() { var authChannel = new Channel(_host, ChannelCredentials.Insecure); _authClient = new Auth.AuthClient(authChannel); var authRes = _authClient.Authenticate(new AuthenticateRequest { Name = _username, Password = _password }); var shutdownAsync = authChannel.ShutdownAsync(); shutdownAsync.Dispose(); _authToken = authRes.Token; _headers = new Metadata { { "Authorization", _authToken } }; }
public void OnAuthorization(AuthorizationFilterContext filterContext) { try { var skipAuthorization = (filterContext.ActionDescriptor as ControllerActionDescriptor) .MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true); if (skipAuthorization.Length > 0) { return; } var tokenString = filterContext.HttpContext.Request.Headers["Authorization"].ToString(); if (string.IsNullOrWhiteSpace(tokenString)) { throw new UnauthorizedAccessException(); } var response = Task.Run(async() => await GrpcCallerService.CallService(urlGrpc: GRPCUrl.IdentityService, logger: null, func: async channel => { var client = new Auth.AuthClient(channel); return(await client.ValidTokenAsync(new TokenRequest { Token = tokenString })); })) .ConfigureAwait(false).GetAwaiter().GetResult(); if (!response.IsValid) { throw new UnauthorizedAccessException(); } SetClaim(filterContext: filterContext, response: response); } catch (Exception ex) { throw new UnauthorizedAccessException(); } }