コード例 #1
0
        public async Task <IActionResult> RichiestaWs()
        {
            try
            {
                string richiestaJson = await Request.GetRawBodyStringAsync();

                if (richiestaJson == null)
                {
                    logger.LogError("RichiestaWs: Contenuto Body Nullo - Ip: " + accessor.HttpContext.Connection.RemoteIpAddress);
                    return(ActionResultGenerator.GeneraRisposta("Contenuto Nullo", TipoDiRisposta.Nok));
                }

                //Passa il json al metodo dell'assembly referenziato (vb) e riceve la risposta
                return(ActionResultGenerator.GeneraRisposta(GestisciRichiesta(richiestaJson), TipoDiRisposta.Ok));
            }
            catch (Exception ex)
            {
                logger.LogError("RichiestaWs: " + ex + " - Ip: " + accessor.HttpContext.Connection.RemoteIpAddress);
                return(ActionResultGenerator.GeneraRisposta(ex.ToString(), TipoDiRisposta.Nok));
            }
        }
コード例 #2
0
        public async Task <IActionResult> CreateBearerToken()
        {
            string richiestaJson = await Request.GetRawBodyStringAsync();

            if (richiestaJson == null)
            {
                logger.LogError("CreateBearerToken: Contenuto Nullo - Ip: " + accessor.HttpContext.Connection.RemoteIpAddress);
                return(ActionResultGenerator.GeneraRisposta("Contenuto Nullo", TipoDiRisposta.Nok));
            }

            BearerTokenLoginModel bearerTokenLoginModel = JsonConvert.DeserializeObject <BearerTokenLoginModel>(richiestaJson);

            if (bearerTokenLoginModel != new BearerTokenLoginModel(username, password))
            {
                logger.LogError("CreateBearerToken: Credenziali Errate - Ip: " + accessor.HttpContext.Connection.RemoteIpAddress);
                return(Unauthorized());
            }

            try
            {
                JwtToken token = new JwtTokenBuilder()
                                 .AddSecurityKey(JwtSecurityKey.Create(key))
                                 .AddSubject("Angel")
                                 .AddIssuer("Angel")
                                 .AddAudience("Angel")
                                 .AddClaim("AngelId", "1000")
                                 .AddExpiry(expiryInMinutes)
                                 .Build();

                logger.LogInformation("CreateBearerToken: Richiesta Token da Ip: " + accessor.HttpContext.Connection.RemoteIpAddress);
                return(ActionResultGenerator.GeneraRisposta(token.Value, TipoDiRisposta.Ok));
            }
            catch (Exception ex)
            {
                return(Ok(ex.ToString()));
            }
        }