From 56382360dfd76ce2e41423a64fdb689b133da88a Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Wed, 19 Nov 2025 10:19:12 +0000 Subject: [PATCH] feat: Add CognitoIdp::Token#refresh_token --- lib/cognito_idp/token.rb | 3 ++- spec/cognito_idp/token_spec.rb | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cognito_idp/token.rb b/lib/cognito_idp/token.rb index 6142e8b..27a6993 100644 --- a/lib/cognito_idp/token.rb +++ b/lib/cognito_idp/token.rb @@ -2,7 +2,7 @@ module CognitoIdp class Token - attr_reader :access_token, :id_token, :token_type, :expires_at, :expires_in + attr_reader :access_token, :id_token, :token_type, :expires_at, :expires_in, :refresh_token def initialize(token_hash) token_hash.transform_keys(&:to_sym).tap do |values| @@ -10,6 +10,7 @@ def initialize(token_hash) @id_token = values[:id_token] @token_type = values[:token_type] @expires_in = values[:expires_in] + @refresh_token = values[:refresh_token] end @expires_at = Time.now + expires_in unless expires_in.nil? end diff --git a/spec/cognito_idp/token_spec.rb b/spec/cognito_idp/token_spec.rb index d19f78c..fb072d3 100644 --- a/spec/cognito_idp/token_spec.rb +++ b/spec/cognito_idp/token_spec.rb @@ -14,6 +14,7 @@ it { expect(token.token_type).to be_nil } it { expect(token.expires_in).to be_nil } it { expect(token.expires_at).to be_nil } + it { expect(token.refresh_token).to be_nil } context "when token is initialized with values" do let(:token_hash) do @@ -21,7 +22,8 @@ "access_token" => "eyJra1example", "id_token" => "eyJra2example", "token_type" => "Bearer", - "expires_in" => 3600 + "expires_in" => 3600, + "refresh_token" => "refresh-token-1" } end @@ -38,5 +40,6 @@ it { expect(token.token_type).to eq("Bearer") } it { expect(token.expires_in).to eq(3600) } it { expect(token.expires_at).to eq(Time.now + 3600) } + it { expect(token.refresh_token).to eq("refresh-token-1") } end end