kamranayub / igdb-dotnet

.NET Core SDK for IGDB V4 API
Apache License 2.0
72 stars 14 forks source link

Support for private endpoints #2

Closed jmorgannz closed 4 years ago

jmorgannz commented 5 years ago

Would be great to explicitly support authentication required for private endpoints - or at the least mention in the README.md that they are not supported (yet)

kamranayub commented 5 years ago

I believe you can handle this currently, by adding the Authorization header using the raw RestEase client from the docs:

var client = new RestClient("https://api-v3.igdb.com", async (request, cancellationToken) =>
{
    // See if the request has an authorize header
    var auth = request.Headers.Authorization;
    if (auth != null)
    {
        // The AquireTokenAsync call will prompt with a UI if necessary
        // Or otherwise silently use a refresh token to return a valid access token
        var token = await context.AcquireTokenAsync("http://my.service.uri/app", "clientId", new Uri("callback://complete")).ConfigureAwait(false);
        request.Headers.Authorization = new AuthenticationHeaderValue(auth.Scheme, token);
  }
}) {
  JsonSerializerSettings = IGDB.Client.DefaultJsonSerializerSettings
};

var api = client.For<IGDB.IGDBApi>();
api.ApiKey = apiKey;
return api;

It's a bit more work and I plan to add this! For now this should work I think.

jmorgannz commented 5 years ago

Thanks, appreciate the sample code - figured it was likely the underlying RestEase client could be manipulated to do it. Was more leaning towards it having a mention in the README.md to prevent others asking the same question.

Guess I could do a pull request if I really thought it was important, haha.

Now, to convince IMDB to grant me a client key and secret 😨

kamranayub commented 4 years ago

Heads up, in IGDBv4 they've removed all private endpoints, so this will be closed once I release v4.