How to get an authentication token, just by sending the userName (Active Directory)

1

I have my code that generates the apiToken, but this requires a userName and password, it works correctly if the correct data is sent, what I want to achieve is that I generate that token but only with the user of the active directory, because of echo I have been unable to get the password, then I'm just sending my userName and it does not generate it; Any solution or recommendation to achieve what I want?

 public async Task<string> GetApiTokenAsync(string userName, string password)
    {
        using (var client = new HttpClient())
        {
            //Setup Cliente
            var apiBaseUri = ConfigurationManager.AppSettings["apiBaseUri"].ToString();
            client.BaseAddress = new Uri(apiBaseUri);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var result = await client.PostAsync("Token", new StringContent("grant_type=password&username=" + userName + "&password=" + password, Encoding.UTF8));

            //get acces token from response body
            var responseJson = await result.Content.ReadAsStringAsync();
            return responseJson;
        }
    }
    
asked by Kmiilo Berrio Montoya 21.11.2016 в 14:39
source

0 answers