コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #4
0
ファイル: AccountService.cs プロジェクト: boxsie/DotNexus
 public AccountService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }
コード例 #5
0
ファイル: TokenService.cs プロジェクト: boxsie/DotNexus
 public TokenService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }
コード例 #6
0
ファイル: LedgerService.cs プロジェクト: boxsie/DotNexus
 public LedgerService(NexusNode node, ILogger <NexusService> log) : base(node, log)
 {
 }