I am trying to make a post call to get the token using /token API
I am doing this using .net core.
the call works when I do it using postman
here are the parameters I am passing
Here are the headers I am passing
the authorization header is the client_id and client_Secret 64 encoded
postman returns a token back
Now I am trying to do this programmatic in .net core. But I keep getting bad request. what am I doing wrong. here is the code making the call
public async Task InvokeAsync(HttpContext context)
{
if (context.Request.Path.Equals("/signin-oidc"))
{
var query = context.Request.Query["code"];
using (HttpClient tokenClient = new HttpClient())
{
string url = "https://{domain}.oktapreview.com/oauth2/afsfjru5uvj6eHSM9c0h7/v1/token";
var parameters = new Dictionary<string, string> { { "redirect_uri", _config.redirectUri }, { "code", query }, { "grant_type", "authorization_code" } };
var encodedContent = new FormUrlEncodedContent(parameters);
tokenClient.DefaultRequestHeaders.Add("Accept", "application/json");
string secretsEncoded = Base64Encode(_config.clientId + ":" + _config.clientSecret);
tokenClient.DefaultRequestHeaders.Add("authorization", "Basic " + secretsEncoded);
var task = tokenClient.PostAsync(url, encodedContent);
task.Wait();
var result = task.Result;
}