seraphx2 / ESI.NET

A C# wrapper for the Eve Online ESI API.
https://www.nuget.org/packages/ESI.NET/
MIT License
40 stars 23 forks source link

Need help figuring out the SSO #57

Closed panthernet closed 1 year ago

panthernet commented 1 year ago

Hi, currently I'm getting this error. I suppose the request should return a JSON but looks like I'm getting some binary rubbish.

R: ?code=ox15HMhqmEqMQk26dRyhP1&state=JrQ1R2TsXxxnPnIWrRAQ3zj6ijUpD13i

      Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: . Path '', line 0, position 0.
         at Newtonsoft.Json.JsonTextReader.ParseValue()
         at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
         at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
         at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
         at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
         at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
         at ESI.NET.SsoLogic.GetToken(GrantType grantType, String code, String codeChallenge) in D:\Projects\MyProjects\EVE\UFIT\ESI.NET\ESI.NET\Logic\_SSOLogic.cs:line 133

Here're the code scaps:

        [Route("auth")]
        public async Task<string> Index()
        {
             await EsiClient.SSO.GetToken(GrantType.AuthorizationCode, ControllerContext.HttpContext.Request.Query["code"]);
        }

image

panthernet commented 1 year ago

Still have that problem. Seems like every SSO related request in the lib fails. Meanwhile if I replace request code in GetToken method with this - it works.

using (var ssoClient = new HttpClient())
{
    ssoClient.DefaultRequestHeaders.Add("User-Agent", "BELLA");
    var values = new Dictionary<string, string> { { "grant_type", "authorization_code" }, { "code", $"{code}" } };

    ssoClient.DefaultRequestHeaders.Add("Authorization", $"Basic {_clientKey}");
    var content = new FormUrlEncodedContent(values);

    using (var tokenresponse = await ssoClient.PostAsync("https://login.eveonline.com/v2/oauth/token", content))
    {
        var responseString = await tokenresponse.Content.ReadAsStringAsync();
        var token = JsonConvert.DeserializeObject<SsoToken>(responseString);
        return token;
    }
}
seraphx2 commented 1 year ago

You have no need to add the headers for user agent or authorization yourself. First step is to setup your app according to the README file. There is an EsiConfig object that needs to be setup properly for this to work.

panthernet commented 1 year ago

You have no need to add the headers for user agent or authorization yourself. First step is to setup your app according to the README file. There is an EsiConfig object that needs to be setup properly for this to work.

I have it done ofcause. Still I have the same result. I had to clone the source code and change the request code for the one shown above to make it work. It is a code from my older project. Strangely your lib doesn't work for me out of the box.

Btw it returns code 200 and I use all the data from your config. Hmmm except user agent maybe.

panthernet commented 1 year ago

I wonder what might cause this behavior? Because changing the request code makes it work.

panthernet commented 1 year ago

@seraphx2 image These two lines cause described behavior for SSO. Once I comment them all work as intended. At least for SSO. Haven't probed other methods as I want to deal with auth first.

So I guess you need a separate HttpClient with corrected settings to work with login.eveonline.com It's been a while since I played with EVE API so I might miss the point in my conclusion. Cheers.

panthernet commented 1 year ago

Nope. These two baddies also spoils corporation requests to API for me, hm.

seraphx2 commented 1 year ago

Can you join the Discord channel to talk about this further? It is easier than going back and forth here.