Skip to content

Commit a12cf87

Browse files
committed
feat: Add CognitoIdp::Token#refresh_token
1 parent d480dad commit a12cf87

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/cognito_idp/token.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
module CognitoIdp
44
class Token
5-
attr_reader :access_token, :id_token, :token_type, :expires_at, :expires_in
5+
attr_reader :access_token, :id_token, :token_type, :expires_at, :expires_in, :refresh_token
66

77
def initialize(token_hash)
88
token_hash.transform_keys(&:to_sym).tap do |values|
99
@access_token = values[:access_token]
1010
@id_token = values[:id_token]
1111
@token_type = values[:token_type]
1212
@expires_in = values[:expires_in]
13+
@refresh_token = values[:refresh_token]
1314
end
1415
@expires_at = Time.now + expires_in unless expires_in.nil?
1516
end

spec/cognito_idp/token_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
it { expect(token.token_type).to be_nil }
1515
it { expect(token.expires_in).to be_nil }
1616
it { expect(token.expires_at).to be_nil }
17+
it { expect(token.refresh_token).to be_nil }
1718

1819
context "when token is initialized with values" do
1920
let(:token_hash) do
2021
{
2122
"access_token" => "eyJra1example",
2223
"id_token" => "eyJra2example",
2324
"token_type" => "Bearer",
24-
"expires_in" => 3600
25+
"expires_in" => 3600,
26+
"refresh_token" => "refresh-token-1"
2527
}
2628
end
2729

@@ -38,5 +40,6 @@
3840
it { expect(token.token_type).to eq("Bearer") }
3941
it { expect(token.expires_in).to eq(3600) }
4042
it { expect(token.expires_at).to eq(Time.now + 3600) }
43+
it { expect(token.refresh_token).to eq("refresh-token-1") }
4144
end
4245
end

0 commit comments

Comments
 (0)