Here we’ll see, step by step, how to use saved tokens from a previous login.
In the following steps, I will admit you saved somewhere your tokens, closed the previous python interpreter and opened a new one.
Like in the login example, we’ll need to create the esipy objects before beeing able to do anything.
from esipy import EsiApp
from esipy import EsiClient
from esipy import EsiSecurity
app = EsiApp().get_latest_swagger
# replace the redirect_uri, client_id and secret_key values
# with the values you get from the STEP 1 !
security = EsiSecurity(
redirect_uri='callback URL',
client_id='you client id',
secret_key='the_secret_key',
)
# and the client object, replace the header user agent value with something reliable !
client = EsiClient(
retry_requests=True,
header={'User-Agent': 'Something CCP can use to contact you and that define your app'},
security=security
)
Now everything is ready, it’s time to update the security object.
As it probably pasts more than 20minute, we’ll assume the access_token is expired so we will only care about the refresh_token
# to update the security object,
security.update_token({
'access_token': '', # leave this empty
'expires_in': -1, # seconds until expiry, so we force refresh anyway
'refresh_token': 'YOUR_SAVED_REFRESH_TOKEN'
})
Now that we updated the security object, we have 2 choices:
EsiClient.request()
So we want to manually refresh the tokens, we just have to call one method to do this:
tokens = security.refresh()
The tokens
variable now contains your access token, refresh token, and the seconds left until expiry.
By doing this, your security object also knows these tokens and will use them automatically when doing requests
print tokens
{
"access_token": "frenafeifafrbaefluerbfeainb",
"token_type": "Bearer",
"expires_in": 1200,
"refresh_token": "fera48ftea4at64fr684fae"
}