Login to WordPress REST API c# with Oauth2

I’m trying to connect to the WordPress REST APi using a c# application. I’m not working with the WordPress servers, however I have it with the newer version installated on my PC. Also I have the Jetpack plugin to be able to use the standard REST API (it works as it was installed on WordPress servers).
Then I went to : https://developer.wordpress.com/apps/ to create an app to have the client id, the client secret and etc.

Then I wrote the following code, to make a Oauth2 login:

Read More
        HttpClient client = new HttpClient();
        string myUser = "my user";
        string myPass = "my pass";
        string clientId = "my client id";
        string redirectUri = "my redirect uri";

        FormUrlEncodedContent form = new FormUrlEncodedContent(new Dictionary<string, string> {
            { "username", myUser }, { "password", myPass }
        });

        Task<HttpResponseMessage> message = client.PostAsync("https://public-api.wordpress.com/oauth2/authorize?client_id=your_client_id" +
            clientId + "&redirect_uri=" + redirectUri + "&response_type=code", form);
        String result = message.Result.Content.ReadAsStringAsync().Result;

        JObject obj = JObject.Parse(result);
        string token = (string)obj["access_token"];
        string refreshToken = (string)obj["refresh_token"];

However, I’m experiencing problems, the variable called “Result”, contains an html saying:

Invalid request, please go back and try again.
Error Code: invalid_client
Error Message: Unknown client_id 

I’m not sure what is wrong, maybe I’m missing the client secret somewhere. Anyone has an idea of what can be wrong? Or anyone knows a better approach to do this?

Lot of thanks in advance

Related posts