On this line, var response = client.PostAsync(APP_PATH + "/Token", content).Result; I get a response equal to:

 {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache X-SourceFiles: =?UTF-8?B?WjpceHh4XHByb2plY3R2aXN1YWxzdHVkaW8tQXJnaGhoTm90ZVxXZWJBcHBsaWNhdGlvbkFub25pbXVzMFxXZWJBcHBsaWNhdGlvbi5XRUJcVG9rZW4=?= Cache-Control: no-cache Date: Fri, 03 Mar 2017 16:40:05 GMT Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET Content-Length: 138 Content-Type: application/json; charset=UTF-8 Expires: -1 }} 

.

 static Dictionary<string, string> GetTokenDictionary(string userName, string password) { var pairs = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>( "grant_type", "password" ), new KeyValuePair<string, string>( "username", userName ), new KeyValuePair<string, string> ( "Password", password ) }; var content = new FormUrlEncodedContent(pairs); using (var client = new HttpClient()) { try { var response = client.PostAsync(APP_PATH + "/Token", content).Result; var result = response.Content.ReadAsStringAsync().Result; // Десериализация полученного JSON-объекта Dictionary<string, string> tokenDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(result); return tokenDictionary; 

result equals:

"{\" error \ ": \" invalid_grant \ ", \" error_description \ ": \" The username or password is incorrect. \ "}"

  • Because the name or password ... wrong? - Artyom Okonechnikov
  • They are introduced correctly - codename0082016
  • one
    If the "correct password" is entered in the same way as the previous comment, it is not surprising :). Maybe there verification is case-sensitive: "username / Password". - Igor

1 answer 1

The username should be an email address, not his name.