public ILibraryAppletAccessor(AppletId appletId, Horizon system)
        {
            _stateChangedEvent = new KEvent(system);

            _applet  = AppletManager.Create(appletId, system);
            _inData  = new AppletFifo <byte[]>();
            _outData = new AppletFifo <byte[]>();

            _applet.AppletStateChanged += OnAppletStateChanged;

            Logger.PrintInfo(LogClass.ServiceAm, $"Applet '{appletId}' created.");
        }
Esempio n. 2
0
        public async ValueTask <IActionResult> Refresh(string key)
        {
            var applet = AppletManager.GetApplet(key, this.HttpContext.RequestServices);

            if (applet == null)
            {
                return(this.NotFound());
            }

            var credential = await applet.GetCredentialAsync(true);

            return(string.IsNullOrEmpty(credential) ? this.NoContent() : this.Content(credential));
        }
Esempio n. 3
0
        public ILibraryAppletAccessor(AppletId appletId, Horizon system)
        {
            _stateChangedEvent       = new KEvent(system.KernelContext);
            _normalOutDataEvent      = new KEvent(system.KernelContext);
            _interactiveOutDataEvent = new KEvent(system.KernelContext);

            _applet = AppletManager.Create(appletId, system);

            _normalSession      = new AppletSession();
            _interactiveSession = new AppletSession();

            _applet.AppletStateChanged        += OnAppletStateChanged;
            _normalSession.DataAvailable      += OnNormalOutData;
            _interactiveSession.DataAvailable += OnInteractiveOutData;

            Logger.PrintInfo(LogClass.ServiceAm, $"Applet '{appletId}' created.");
        }
Esempio n. 4
0
        public async ValueTask <IActionResult> GetPhoneNumber(string key, string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(this.BadRequest());
            }

            var applet = AppletManager.GetApplet(key, this.HttpContext.RequestServices);

            if (applet == null)
            {
                return(this.NotFound());
            }

            var result = await applet.GetPhoneNumberAsync(token);

            return(result.Succeed ? this.Ok(result.Value) : this.NotFound(result.Failure));
        }
Esempio n. 5
0
        public async ValueTask <IActionResult> Login(string key)
        {
            var token = await this.Request.ReadAsStringAsync();

            if (string.IsNullOrEmpty(token))
            {
                return(this.BadRequest());
            }

            var applet = AppletManager.GetApplet(key, this.HttpContext.RequestServices);

            if (applet == null)
            {
                return(this.NotFound());
            }

            var result = await applet.LoginAsync(token);

            return(result.Succeed ? this.Ok(new { Applet = applet.Account.Code, result.Value.Identifier }) : this.NotFound(result.Failure));
        }
        public async ValueTask <OperationResult <Token> > VerifyAsync(string key, Ticket ticket, string scenario, CancellationToken cancellation = default)
        {
            if (ticket.IsEmpty)
            {
                return(OperationResult.Fail("InvalidTicket"));
            }

            switch (ticket.Scheme?.ToLowerInvariant())
            {
            case "applet":
                var applet = AppletManager.GetApplet(key, this.ServiceProvider);

                if (applet == null)
                {
                    return(key != null && key.Contains(':') ?
                           OperationResult.Fail("NotFound", $"The specified '{key}' applet does not exist.") :
                           OperationResult.Fail("NotFound", $"The specified '{key}' account does not exist."));
                }

                return(await GetAppletToken(applet, key, ticket.Token, cancellation));

            case "channel":
                var channel = ChannelManager.GetChannel(key, this.ServiceProvider);

                if (channel == null)
                {
                    return(key != null && key.Contains(':') ?
                           OperationResult.Fail("NotFound", $"The specified '{key}' channel does not exist.") :
                           OperationResult.Fail("NotFound", $"The specified '{key}' account does not exist."));
                }

                return(await GetChannelToken(channel, key, ticket.Token, cancellation));

            default:
                return(OperationResult.Fail("InvalidTicket", $"The specified ‘{ticket.Scheme}’ ticket scheme is not recognized."));
            }
        }