# Mautic 3 - c# authentication issue: The client credentials are invalid

**URL:** <https://forum.mautic.org/t/mautic-3-c-authentication-issue-the-client-credentials-are-invalid/19189>\
**Category:** Development\
**Tags:** development, mautic-3\
**Created:** [April 26, 2021, 5:02pm UTC](https://forum.mautic.org/t/mautic-3-c-authentication-issue-the-client-credentials-are-invalid/19189 "2021-04-26T17:02:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nimeshvaghasiya](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nimeshvaghasiya](https://forum.mautic.org/u/nimeshvaghasiya)\
**Post date:** [April 26, 2021, 5:02pm UTC](https://forum.mautic.org/t/mautic-3-c-authentication-issue-the-client-credentials-are-invalid/19189/1 "2021-04-26T17:02:40Z")

</div>

Anybody work on Mautic api with c# or [asp.net](http://asp.net) core?

I’m checking it on localhost for Mautic production one. I got below error even I have pass correct credentials. I have checked with both Get/Post requests.

It throws:

```
{"errors":[{"message":"The client credentials are invalid","code":400,"type":"invalid_client"}]}

```

I found related issue [here](https://github.com/mautic/mautic/issues/9628): but it didn’t help

Code:

```
        try
        {
            using (var client = new HttpClient())
            {
                var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8012/mautic/oauth/v2/token");
                    request.Content = new FormUrlEncodedContent(new Dictionary<string, string> {
                    { "client_id", "key" },
                    { "client_secret", "secret" },
                    { "grant_type", "authorization_code" },
                    { "redirect_uri", Uri.EscapeUriString("http://localhost")},
                    { "code", DateTime.Now.ToString("ddMMyyyyHHmmss") }
                });

                var authenticationBytes = Encoding.ASCII.GetBytes("admin:123qwe");

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                        Convert.ToBase64String(authenticationBytes));

                var response = await client.SendAsync(request);
                

                var responsestring = await response.Content.ReadAsStringAsync();
                var payload = JObject.Parse(responsestring);
                var token = payload.Value<string>("access_token");
            }

        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
```
