Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests to endpoints that don't need authorisation fail when passing client details #12

Open
matthewpennell opened this issue Oct 14, 2017 · 6 comments

Comments

@matthewpennell
Copy link

I'm finding that using an EsiAuthentication object when creating the Eseye object causes requests to endpoints that don't need authorisation to fail.

Here's a snippet of code:

// Set config datasource using environment variable.
$configuration = Configuration::getInstance();
$configuration->datasource = env('ESEYE_DATASOURCE', 'tranquility');

// Create authentication with app details and refresh token from user 1.
$user = User::first();

$authentication = new EsiAuthentication([
    'secret'        => env('TESTEVEONLINE_CLIENT_SECRET'),
    'client_id'     => env('TESTEVEONLINE_CLIENT_ID'),
    'refresh_token' => $user->refresh_token,
]);

// Create ESI API object.
$esi = new Eseye($authentication);
        
// Retrieve the user's character details.
$character = $esi->invoke('get', '/characters/{character_id}/', [
    'character_id' => $user->eve_id,
]);

The call to the basic character information endpoint throws an error: invalid_client: Unknown client.

If I remove the EsiAuthentication from the object creation, it works fine. However, I want to be able to create a single Eseye object and use that for all calls, not have to juggle different ones. This is basically the same code as your example, so I can't see why it wouldn't be working.

@leonjza
Copy link
Member

leonjza commented Oct 14, 2017

Hey!

Thanks for the report! I am getting closer to moving this library into SeAT core as well and will most probably come across this too. Let me debug and see whats happening / what can be done to make it more bazinga!

@matthewpennell
Copy link
Author

Actually I think I figured it out myself just now. :)

I added in the scopes and token_expires keys to the EsiAuthentication creation call, and now it accepts the request. I think it might have been because the default token_expires value was being created as Unix epoch 1970, so the auth was immediately out-of-date.

Here's my code:

$authentication = new EsiAuthentication([
    'secret'        => env('TESTEVEONLINE_CLIENT_SECRET'),
    'client_id'     => env('TESTEVEONLINE_CLIENT_ID'),
    'access_token'  => $new_token->access_token,
    'refresh_token' => $user->refresh_token,
    'scopes'        => [
                        'esi-industry.read_corporation_mining.v1',
                        'esi-wallet.read_corporation_wallet.v1',
                        'esi-mail.send_mail.v1',
                    ],
    'token_expires' => date('Y-m-d H:i:s', time() + $new_token->expires_in),
]);

$new_token is the refreshed token from the EVE oauth server, btw.

@leonjza
Copy link
Member

leonjza commented Dec 29, 2017

@matthewpennell you are 100% correct. However, I am expecting the expired token due to the default epoch to trigger the automatic refresh token logic, just like you are doing outside of Eseye with the EsiAuthentication setup.

I'll test to see if I can replicate this.

@charlesander
Copy link

Hello there,
I'm just letting you know that I had this same issue today, and I was unable to debug it myself due to the error being so opaque. Following matthewpennell's solution fixed this for me.

Perhaps you could update the docs to say that the extra fields might be needed in some situations?

P.S. thanks for the work you've put into this library :-)

@GeezerUK
Copy link

Actually I think I figured it out myself just now. :)

I added in the scopes and token_expires keys to the EsiAuthentication creation call, and now it accepts the request. I think it might have been because the default token_expires value was being created as Unix epoch 1970, so the auth was immediately out-of-date.

Here's my code:

$authentication = new EsiAuthentication([
    'secret'        => env('TESTEVEONLINE_CLIENT_SECRET'),
    'client_id'     => env('TESTEVEONLINE_CLIENT_ID'),
    'access_token'  => $new_token->access_token,
    'refresh_token' => $user->refresh_token,
    'scopes'        => [
                        'esi-industry.read_corporation_mining.v1',
                        'esi-wallet.read_corporation_wallet.v1',
                        'esi-mail.send_mail.v1',
                    ],
    'token_expires' => date('Y-m-d H:i:s', time() + $new_token->expires_in),
]);

$new_token is the refreshed token from the EVE oauth server, btw.

Just come across this is it possible you can show your full page code

@matthewpennell
Copy link
Author

Just come across this is it possible you can show your full page code

This is the relevant file in my application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants