This repository was archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Tokens: Manual
Josh Freeman edited this page Jun 4, 2019
·
2 revisions
This describes the process of manually getting a token, which involves:
- Sending a random ID that is correctly signed to the SE Token server
- SE will send you the token back + a login url
- The Login url is what the Companion App uses, it's secure and on SE's official servers
- You can open the Login URL in your browser and use your normal SE Credentials.
use Companion\CompanionApi;
// Initialise the API. We provide no token parameter so it creates a blank one
$api = new CompanionApi();
// Request an SE Login URL
$loginUrl = $api->Account()->getLoginUrl();
// We can grab our token to use later on
$sightToken = $api->Token()->get();
echo "Token: {$sightToken->token} \n"
echo "Login URL: {$loginUrl} \n";
The variable $loginUrl
will be the url to the secure Square-Enix login form. When you open it one of two things will happen based on existing cookies in your browser:
- If you have never logged in before then a login form will appear. Login with your Square-Enix account and it will set cookies, authenticate the token and return a status code of either
200
or202
. (Usually it sends 202, then if you refresh it will switch to 200) - If you've already logged in previously, you'll automatically login and be redirected straight to the status code response.
Once you have a 200
or 202
status, your $token
will be valid for roughly 18 hours (View Tokens: Expiry wiki page for more on this)
At this point you can save your token as it will have been updated
$sightToken = $api->Token()->get();
// json encode it
$sightToken = json_encode($sightToken);
// save it
file_put_contents(__DIR__.'/my_token.json', $sightToken);
You can save the JSON Encoded/Serialised version of SightToken
anywhere (db, s3, file, etc..)