okta / okta-sdk-python

Apache License 2.0
229 stars 143 forks source link

Feature: Autorenew OAuth tokens #402

Open jccaldw1 opened 1 month ago

jccaldw1 commented 1 month ago

Currently, when a Client is initialized with OAuth configuration, as below:

config = {
    'orgUrl': 'https://{yourOktaDomain}',
    'authorizationMode': 'PrivateKey',
    'clientId': '{yourClientId}',
    'scopes': ['okta.users.manage'],
    'privateKey': 'YOUR_PRIVATE_JWK', # this parameter should be type of str
    'kid': 'YOUR_PRIVATE_KEY_ID' # if a key ID needs to be provided, it can be provided here or part of the privateKey under "kid"
}

An expired OAuth JWT token can be used if the client lives for long enough. This PR adds an additional check to see if the stored OAuth token is expired - if it is, we go through the normal token generation process and save the resultant token in self._access_token in the OAuth object. This will ensure that OAuth access tokens are never expired.