bug/WP-1010: Token refresh fails when Tapipy client cannot be instantiated #1575
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Overview:
We’ve had multiple instances where a user has a faulty Tapis access token but their refresh token is still valid. In these cases a Tapipy client cannot be instantiated (the telltale error is a 404 when listing tenants in this method). The token can only be refreshed by calling the Tapis /oauth2/tokens endpoint directly, after which their new access token is added to the Django user model.
PR Status:
Related Jira tickets:
Summary of Changes:
Catch the exception that occurs when a Tapipy client fails to instantiate, and attempt a token refresh using a direct call to the Tapis API.
Testing Steps:
Inside the Django shell:
from django.contrib.auth import get_user_model()user = get_user_model().objects.get(username=<your username>)user.tapis_oauth.refresh_tokens_api()These steps should proceed without error and the
createddate on your user's access token should match when the refresh method was called.UI Photos:
Notes: