# Get token using .net 6 code

**URL:** <https://community.auth0.com/t/get-token-using-net-6-code/98555>\
**Category:** Get Help\
**Created:** [January 20, 2023, 8:30am UTC](https://community.auth0.com/t/get-token-using-net-6-code/98555 "2023-01-20T08:30:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Circle](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/circle/32/42831_2.png) [@Circle](https://community.auth0.com/u/Circle)\
**Post date:** [January 20, 2023, 8:30am UTC](https://community.auth0.com/t/get-token-using-net-6-code/98555/1 "2023-01-20T08:30:05Z")

</div>

Hi Everyone,

Have an issue getting the token from my .net 6 application. I am using the following sample code provided by Auth0:

```auto
var client = new RestClient("https://mydomain/oauth/token");
        var request = new RestRequest { Method = Method.Post };
        request.AddHeader("content-type", "application/json");
        request.AddParameter("application/json", "{\"client_id\":\"myclientid\",\"client_secret\":\"mysecret\",\"audience\":\"myaudience\",\"grant_type\":\"client_credentials\"}", ParameterType.RequestBody);
        var response = client.Execute(request);

```

but am getting a response with the following exception:

```auto
The message received was unexpected or badly formatted.
at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__175`1.MoveNext()
   at System.Net.Security.SslStream.<ReplyOnReAuthenticationAsync>d__173`1.MoveNext()
   at System.Net.Security.SslStream.<ReadAsyncInternal>d__188`1.MoveNext()

```

I have tried enabling/disabling different security protocols for TLS, but with no luck. According to found articles it has to do with the incompatible cipher suite. Am I missing any configuration for that?

---

<div class="post-metadata">

**Author:** ![Circle](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/circle/32/42831_2.png) [@Circle](https://community.auth0.com/u/Circle)\
**Post date:** [January 22, 2023, 6:07pm UTC](https://community.auth0.com/t/get-token-using-net-6-code/98555/2 "2023-01-22T18:07:47Z")

</div>

Was able to solve the problem, so just in case someone needs it, here is the code which works:

```auto
var handler = new HttpClientHandler();
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;

var httpClient = new HttpClient(handler);
var result = await httpClient.PostAsJsonAsync("https://mydomain/oauth/token",
            new TokenRequestDto
            {
                client_id = "myclientid",
                client_secret = "mysecret",
                audience = "myaudience",
                grant_type = "client_credentials"
            });

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2023, 11:06am UTC](https://community.auth0.com/t/get-token-using-net-6-code/98555/3 "2023-01-26T11:06:16Z")

</div>

Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2023, 11:06am UTC](https://community.auth0.com/t/get-token-using-net-6-code/98555/4 "2023-01-26T11:06:20Z")

</div>


