Invalid client error


I’m trying to get access token, but after sending post request i’m getting error “invalid_client” with description “Unauthorized grant type: client_credentials”. Here is my C# code.

public static async Task GetToken()
string clientId = “id”;
string clientSecret = “secret”;
string credentials = String.Format("{0}:{1}", clientId, clientSecret);

        using (var client = new HttpClient())
            //Define Headers
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
            //Prepare Request Body
            List<KeyValuePair<string, string>> requestData = new List<KeyValuePair<string, string>>();
            requestData.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));

            FormUrlEncodedContent requestBody = new FormUrlEncodedContent(requestData);

            //Request Token
            var request = await client.PostAsync("", requestBody);
            var response = await request.Content.ReadAsStringAsync();
            return response;

Where is the problem?



As far as I understand from the docs, the client credentials grant is automatically used to generate API keys (in the API KEYS section of one of your apps on the developer portal)

You could create a server side API key for your app and then use it like so:
new AuthenticationHeaderValue("Bearer", {your-api-key-here});

Let me know if that works



But i want to send a message to the hub chat and i need access token for this.


I think you are looking for Authorization Code grant? or implicit flow?


Generally I just want to make console application that will be able to post messages on hub chat. I’m not familiar with oauth2, so i don’t really know how can i simply get access token and i don’t know which way should i choose to get it.


Basically, you can’t use your API Key to directly post messages, you need to have an user go through a FACEIT Connect screen to allow your program to post messages on their behalf (this could be you, of course).