SSO 406 error C#

Having a issues with getting the token with the code the response body is empty the status code i get is 406 any ideas? this is a blazer app in c#

@page “/CallBack”
@using System.Linq;
@using System.Net.Http;
@using System.Net.Http.Headers;
@using System.Text;
@using System.Threading.Tasks;
@using Microsoft.AspNetCore.Components;
@using Microsoft.Extensions.Configuration;
@using System.Text.Json;
@using eveFastResponseFleet.Data;
@inject IConfiguration Configuration
@inject NavigationManager navManager

CallBack


@@foreach (var item in Token)
{

@item.access_token
@item.expires_in
@item.token_type
@item.refresh_token

}
@
@code {
private static readonly HttpClient _httpClient = new HttpClient();
private EveSSO Token;
string code { get; set; }
private static HttpClient _client = new HttpClient()
{
};
protected override async Task OnInitializedAsync()
{
var uri = navManager.ToAbsoluteUri(navManager.Uri);
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue(“code”, out var param))
{
code = param.First();
}
byte toBytes = Encoding.ASCII.GetBytes(Configuration[“EsiConfig:ClientId”] + “:” + Configuration[“EsiConfig:SecretKey”]);
string base64 = System.Convert.ToBase64String(toBytes);
var dict = new Dictionary<string, string>();
dict.Add(“grant_type”, “authorization_code”);
dict.Add(“code”, code);
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Basic”, base64);
_httpClient.DefaultRequestHeaders.Host = “login.eveonline.com”;
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(“eve-frf”);
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/x-www-form-urlencoded”));
string body = “grant_type=authorization_code&code=”+code;
var requestMessage = new HttpRequestMessage()
{
Method = new HttpMethod(“POST”),
RequestUri = new Uri(“https://login.eveonline.com/v2/oauth/token”),
Content = new FormUrlEncodedContent(dict)
};
var response = await _httpClient.SendAsync(requestMessage);
var responseStatusCode = response.StatusCode;
var responseBody = await response.Content.ReadAsStringAsync();
Token = JsonSerializer.Deserialize<EveSSO>(responseBody);
}
}

Seems you’re missing the Content-Type: application/x-www-form-urlencoded header. See https://docs.esi.evetech.net/docs/sso/web_based_sso_flow.html for docs on the full flow.

this line should fulfill the requirement but if i remove that line it works so thank you for putting my on the right path

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.