Skip to content

Commit 5d623cf

Browse files
committed
Refresh OAuth ID token when expired
Handles `Aws::STS::Errors::ExpiredTokenException` Fixes #1.
1 parent 5873534 commit 5d623cf

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/aws/google.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def refresh
168168
role_session_name: token_params['email']
169169
)
170170
)
171-
rescue Signet::AuthorizationError => e
171+
rescue Signet::AuthorizationError, Aws::STS::Errors::ExpiredTokenException
172172
retry if (@google_client = google_oauth)
173173
raise
174174
rescue Aws::STS::Errors::AccessDenied => e

test/aws/google_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,24 @@
179179
assert_requested(token_post)
180180
end
181181
end
182+
183+
describe 'expired Google auth token' do
184+
before do
185+
config[:client].stub_responses(
186+
:assume_role_with_web_identity,
187+
[
188+
Aws::STS::Errors::ExpiredTokenException.new(nil, nil),
189+
{ credentials: credentials }
190+
]
191+
)
192+
end
193+
194+
it 'refreshes Google auth token when expired' do
195+
system.times(5)
196+
@oauth_default.once
197+
Aws::Google.any_instance.expects(:google_oauth).returns(oauth).once
198+
Aws::STS::Client.new.config.credentials
199+
end
200+
end
182201
end
183202
end

0 commit comments

Comments
 (0)