I have a strange behavior with this method and the way the server receives the information, can't figure out why it happens.
So I have this simple method that calls the RequestClientCredentialsTokenAsync
private async Task<TokenResponse> Token()
{
var requestBody = new ClientCredentialsTokenRequest()
{
ClientId = "superClientId",
RequestUri = new Uri("http://something"),
GrantType = OpenIdConnectGrantTypes.ClientCredentials,
ClientCredentialStyle = ClientCredentialStyle.PostBody,
ClientAssertion = new ClientAssertion
{
Type = OidcConstants.ClientAssertionTypes.JwtBearer,
Value = "value_created_in_another_place"
}
};
using var httpClient = _httpClientFactory.CreateClient(Options.DefaultName);
return await httpClient.RequestClientCredentialsTokenAsync(requestBody);
}
So this function uses the constant urn:ietf:params:oauth:client-assertion-type:jwt-bearer, and nothing special is going on here.
On the server I got this for handle the requests:
public async Task<IActionResult> Post()
{
using var reader = new StreamReader(Request.Body);
var tokenRequestDto = new TokenRequestDto();
var data = await reader.ReadToEndAsync();
if (string.IsNullOrWhiteSpace(data))
{
return BadRequest();
}
//Other stuff to do...
}
The problem here it's that the constant for some reason gets encoded, so instead of the original string, I get something like this:
grant_type=client_credentials &client_id=superClientId &client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer &client_assertion=...
Already tried to change the StreamReader and passed some encodings, Default, ASCII, UTF8 but in the end I got the same thing.
Just trying to understand why this happens. Anyone has some idea/information?
Thanks