public static async Task <IActionResult> Login([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
        {
            var        requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic    credenciales = JsonConvert.DeserializeObject(requestBody);
            string     clientId     = Environment.GetEnvironmentVariable("clientID", EnvironmentVariableTarget.Process);
            string     scope        = Environment.GetEnvironmentVariable("scope", EnvironmentVariableTarget.Process);
            string     clientSecret = Environment.GetEnvironmentVariable("clientSecret", EnvironmentVariableTarget.Process);
            string     username     = (string)credenciales["username"];
            string     password     = (string)credenciales["password"];
            string     grantType    = "password";
            string     tenant       = Environment.GetEnvironmentVariable("tenant", EnvironmentVariableTarget.Process);
            string     endPoint     = $"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token";
            HttpClient client       = new HttpClient();
            var        parametros   = new Dictionary <string, string> {
                { "client_id", clientId },
                { "scope", scope },
                { "client_secret", clientSecret },
                { "username", username },
                { "password", password },
                { "grant_type", grantType }
            };
            var requestMessage = new HttpRequestMessage(HttpMethod.Post, endPoint);

            requestMessage.Content = new FormUrlEncodedContent(parametros);
            var response = await client.SendAsync(requestMessage);

            var responseBody = await response.Content.ReadAsStringAsync();

            dynamic json = JsonConvert.DeserializeObject(responseBody);

            client.Dispose();
            string accessToken = json.access_token;

            return(ContainerMethods.GetJsonGetContainer(OperationHelper.GetElement(accessToken), log));
        }
示例#2
0
        /// <summary>
        /// Obtiene una entidad desde la base de datos.
        /// </summary>
        /// <param name="id">identificador de la entidad</param>
        /// <returns>Resultado Get</returns>
        public async Task <ExtGetContainer <T> > Get(string id)
        {
            var entity = await repo.GetEntity(id);

            return(OperationHelper.GetElement(entity));
        }