Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Cache generated App Store Connect JSON web tokens to disk #181

Merged
merged 15 commits into from
Dec 27, 2021

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Dec 22, 2021

Sometimes App Store Connect API yields false positive results with regards to authentication. More precisely, requests signed with JSON web tokens that are generated from completely valid API keys can result in a response with status code 401 and content

Authentication credentials are missing or invalid. - Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens

To reduce the chance of this to happen, one way it to add a graceful retry logic (as is done in #178). Another way is to use JSON Web Tokens that are known to work as many times as possible. The changes in this pull request implement the latter approach.

By default App Store Connect API requests initiated by app-store-connect actions try to load JSON Web Token from a file cache instead of generating new token for each individual command invocation. This can be turned off by specifying --disable-jwt-cache option.

Affected actions:

  • All actions and subactions in app-store-connect.

Examples

  • Caching JWT is enabled by default:
$ app-store-connect apps get 1481211155 --verbose
[12:21:00] INFO  > Get App 1481211155
[12:21:00] DEBUG > Load JWT for App Store Connect from disk cache
[12:21:00] DEBUG > Loaded JWT for App Store Connect from disk cache
-- App --
Id: 1481211155
...
  • If cache does not exist, new token is generated
$ app-store-connect apps get 1481211155 --verbose
[12:24:29] INFO  > Get App 1481211155
[12:24:29] DEBUG > Load JWT for App Store Connect from disk cache
[12:24:29] DEBUG > Failed to load App Store Connect JWT from disk cache: Token is not cached
[12:24:29] DEBUG > Generate new App Store Connect JWT
[12:24:29] DEBUG > Cached App Store Connect JWT
-- App --
Id: 1481211155
...
  • Disabled JWT caching
$ app-store-connect apps get 1481211155 --verbose --disable-jwt-cache
[12:21:07] INFO  > Get App 1481211155
[12:21:07] DEBUG > Failed to load App Store Connect JWT from disk cache: Disk cache is disabled
[12:21:07] DEBUG > Generate new App Store Connect JWT
-- App --
Id: 1481211155
...

Docs related to the changes made here are in a separate PR #183.

@priitlatt priitlatt marked this pull request as ready for review December 22, 2021 16:26
@priitlatt
Copy link
Contributor Author

Fixes #176 .

@priitlatt priitlatt marked this pull request as draft December 27, 2021 09:42
@priitlatt priitlatt added the enhancement New feature or request label Dec 27, 2021
@priitlatt priitlatt marked this pull request as ready for review December 27, 2021 10:33
@priitlatt priitlatt changed the base branch from master to v0.15.0 December 27, 2021 10:34
@priitlatt priitlatt merged commit 48fa38a into v0.15.0 Dec 27, 2021
@priitlatt priitlatt deleted the feature/jwt-disk-cache branch December 27, 2021 13:16
priitlatt added a commit that referenced this pull request Dec 28, 2021
* Add option to retry unauthorized App Store Connect requests (#178)

* Docs: Update `app-store-connect` docs with `--api-unauthorized-retries` option (#179)

* Feature: Improve argparse error messages for typed CLI args (#180)

* Feature: Cache generated App Store Connect JSON web tokens to disk (#181)

* Docs: Update `app-store-connect` docs with `--disable-jwt-cache` option (#183)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants