Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async Task <T> GetAsync <T>(HttpContext context) where T : NexusService
        {
            var nexusNode = new NexusNode(_serviceProvider.GetService <INexusClient>(), await _nodeManager.GetCurrentEndpointAsync(context));

            var service = Activator.CreateInstance(typeof(T), nexusNode, _serviceProvider.GetService <ILogger <NexusService> >());

            return((T)service);
        }
Ejemplo n.º 4
0
 public AccountService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }
Ejemplo n.º 5
0
 public TokenService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }
Ejemplo n.º 6
0
 public LedgerService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }