Fixed an issue where expired auth tokens would be used #7756
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.
Description
Previously, getAuthToken never checked expiry, because it was never relevant for short lived commands. Now that VSCode uses this same path, we saw lots of expired auth token issues.
I also added a second line of defense here and get new auth tokens whenever we get a 401 error. This is mostly irrelevant within the CLI (since 401's will generally end the process), but may help VSCE repair itself. With the new validity check, this probably should never be hit.
Scenarios Tested
I was getting 401s when executing queries against prod in VSCE - this fixed that. I also tested out a bunch of CLI commands from various auth states: valid tokens, expired tokens, and using application default credentials