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

[spaceship] decrease App Store Connect API token issued-at-time to prevent server rejection #21583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion spaceship/lib/spaceship/connect_api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def with_asc_retry(tries = 5, backoff = 1, &_block)
if tries.zero?
raise error
else
msg = "Token has expired or has been revoked! Trying to refresh..."
msg = "Token has expired, issued-at-time is in the future, or has been revoked! Trying to refresh..."
puts(msg) if Spaceship::Globals.verbose?
@token.refresh!
retry
Expand Down
3 changes: 2 additions & 1 deletion spaceship/lib/spaceship/connect_api/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def refresh!

payload = {
iss: issuer_id,
iat: now.to_i,
# Reduce the issued-at-time in case our time is slighly ahead of Apple's servers, which causes the token to be rejected.
iat: now.to_i - 60,
exp: @expiration.to_i,
aud: 'appstoreconnect-v1'
}
Expand Down
2 changes: 1 addition & 1 deletion spaceship/spec/connect_api/token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
payload, header = JWT.decode(token.text, key, true, { algorithm: 'ES256' })

expect(payload['iss']).to eq(issuer_id)
expect(payload['iat']).to eq(Time.now.to_i)
expect(payload['iat']).to be < Time.now.to_i
expect(payload['aud']).to eq('appstoreconnect-v1')
expect(payload['exp']).to be > Time.now.to_i

Expand Down