Broken access_token when calling from .net

For some reason, I get a broken access_token in return when I’m trying to make a user authentication through my .net code.
Strangely, the exact same call in POSTMAN works like a charm.
In essence, the broken access_token returned contains 3 dots like ‘…’ somewhere in token rendering it invalid (verified through jwt.io).
Note, that the json has not been truncated since it actually looks complete.
And the HttpStatusCode == OK

The c# code looks like this:

            Dictionary<string, string>? dict = new() {
                { "audience", audience },
                { "grant_type", "password" },
                { "username", username },
                { "password", password },
                { "client_id", clientId },
                { "client_secret", clientSecret }
            };
            
            string payload = JsonConvert.SerializeObject(dict);
            HttpRequestMessage? req = new(HttpMethod.Post, url) { Content = new StringContent(payload, Encoding.UTF8, "application/json")};
            HttpResponseMessage? res = await _httpClient.SendAsync(req);
            string result = await res.Content.ReadAsStringAsync();
            return new (result, res.IsSuccessStatusCode );

The Postman call looks like this:

POST {myurl}
Content-Type: application/json
{
    "client_id": "{my client_id},
    "client_secret": "{my_client_secret}",
    "audience": "{my_audience_in_api},
    "username": "{my_username}",
    "password": "{my_password}",
    "grant_type": "password"
}

Hi @nra,

Could you post an example token? You may be getting an opaque token if your audience isn’t making it into the request.

Hi Dan.

Thanks for reverting back to me.
I must admit the fault is on me.
In VS2022 I was debugging some issues in C# and the debugger played a trick on me when running Blazor limiting the view of the strings.
So the string variables containing the token seemed to contain broken values, but it turned out that when you Console.Writeline the contents, they actually contain the correct value.

So bottomline: When debugging your Blazor app in VS2022 don’t rely 100% on the visible debugger contents. It has nothing to do with Auth0!

Please close this ticket and bear with me :blush:

1 Like

Thanks for following up on this!