Hey,
Thanks for the reply @EveDataRules
I wrote the library. The only aspect which is generated is the API docs which is handled by sami, I’m not a fan of the code generated by swagger.
To answer your first question. Yes it is sent if it’s supplied. However the token is sent in the header and correctly ignored by esi/ccp if not required, if this might cause an issue anyone is aware of please let me know! Taking the public search endpoint /search/
, we can create an authenticated client and query perfectly fine.
$client = \AGrimes94\Esi\EsiClient::create()->authenticate('ACCESS_TOKEN');
$response = $client->search()->searchPublic('Anthony Karnelou', ['character']);
/*
* Results in:
*
* {#598 ▼
* +"reasonPhrase": "OK"
* +"statusCode": 200
* +"headers": array:19 [▶]
* +"body": array:1 [▼
* "character" => array:1 [▶]
* ]
* }
*/
However this authentication step isn’t required if you are only querying public endpoints, so the below also works perfectly.
$client = \AGrimes94\Esi\EsiClient::create();
$response = $client->search()->searchPublic('Anthony Karnelou', ['character']);
/*
* Results in:
*
* {#592 ▼
* +"reasonPhrase": "OK"
* +"statusCode": 200
* +"headers": array:19 [▶]
* +"body": array:1 [▼
* "character" => array:1 [▶]
* ]
* }
*/
To answer your second question. If you need to re-authenticate a client with a different character you can call the authenticate method again on the client passing in the string token.
This will remove the existing authenticate plugin (the plugin handles adding the header to the request) and create a new authenticate plugin with the new information. Therefore subsequent requests will use the new access token.
An example:
// Create a client with our first characters token
$client = \AGrimes94\Esi\EsiClient::create()->authenticate('FIRST_ACCESS_TOKEN');
// Perform an authenticated request
$response = $client->search()->searchPrivate(123123123, 'Anthony Karnelou', ['character']);
// Change the access token in the created client
$client->authenticate('SECOND_ACCESS_TOKEN');
// Perform new request with different token
$response = $client->search()->searchPrivate(123123123, 'Anthony Karnelou', ['character']);