public async Task <IdentityResult> LoginAsync(HttpContext httpContext, NexusNodeEndpoint nodeEndpoint, bool isPersistent = false, CancellationToken token = default) { if (httpContext.User.Identity.IsAuthenticated) { return(IdentityResult.Failed(new IdentityError { Description = "Already signed in" })); } var nexusNode = new NexusNode((INexusClient)httpContext.RequestServices.GetService(typeof(INexusClient)), nodeEndpoint); var response = await nexusNode.Client.GetAsync("ledger/mininginfo", "Connection attempt", null, token, true); if (!response.IsSuccessStatusCode) { return(IdentityResult.Failed(new IdentityError { Description = "Unable to connect to node endpoint" })); } var claims = new List <Claim> { new Claim(_cookeConstants.NodeIdClaimType, nodeEndpoint.Name) }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(IdentityResult.Success); }
public NexusNode(INexusClient nexusClient, NexusNodeEndpoint endpoint) { Client = nexusClient; Endpoint = endpoint; Client.ConfigureHttpClient(endpoint); }
public T Get <T>(NexusNodeEndpoint nodeEndpoint) where T : NexusService { var nexusNode = new NexusNode(_serviceProvider.GetService <INexusClient>(), nodeEndpoint); var service = Activator.CreateInstance(typeof(T), nexusNode, _serviceProvider.GetService <ILogger <NexusService> >()); return((T)service); }
public async Task CreateAsync(NexusNodeEndpoint nodeEndpoint) { if (nodeEndpoint == null) { throw new ArgumentException("Node endpoint data is missing"); } await _repository.CreateNodeAsync(nodeEndpoint); }
public async Task <BlockNotifyJob> CreateBlockNotifyJobAsync(NexusNodeEndpoint endpoint, TimeSpan interval, Func <Block, Task> onNotify, CancellationToken token = default) { var job = new BlockNotifyJob( _loggerFactory.CreateLogger <BlockNotifyJob>(), _serviceFactory.Get <LedgerService>(endpoint), onNotify); await job.StartAsync(interval, token); return(job); }
public Task CreateNodeAsync(NexusNodeEndpoint endpoint) { return(_repository.CreateAsync(endpoint)); }