Class: AtprotoAuth::Token::Refresh

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/atproto_auth/token/refresh.rb

Overview

Handles token refresh operations with retry logic

Constant Summary collapse

MAX_RETRIES =

Maximum number of refresh attempts

3
BASE_DELAY =

Base delay between retries in seconds

1
MAX_DELAY =

Maximum delay between retries in seconds

8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session:, dpop_client:, auth_server:, client_metadata:) ⇒ Refresh

Returns a new instance of Refresh.



66
67
68
69
70
71
72
73
# File 'lib/atproto_auth/token/refresh.rb', line 66

def initialize(session:, dpop_client:, auth_server:, client_metadata:)
  super() # Initialize MonitorMixin
  @session = session
  @dpop_client = dpop_client
  @auth_server = auth_server
  @attempt_count = 0
  @client_metadata = 
end

Instance Attribute Details

#auth_serverObject (readonly)

Returns the value of attribute auth_server.



64
65
66
# File 'lib/atproto_auth/token/refresh.rb', line 64

def auth_server
  @auth_server
end

#client_metadataObject (readonly)

Returns the value of attribute client_metadata.



64
65
66
# File 'lib/atproto_auth/token/refresh.rb', line 64

def 
  @client_metadata
end

#dpop_clientObject (readonly)

Returns the value of attribute dpop_client.



64
65
66
# File 'lib/atproto_auth/token/refresh.rb', line 64

def dpop_client
  @dpop_client
end

#sessionObject (readonly)

Returns the value of attribute session.



64
65
66
# File 'lib/atproto_auth/token/refresh.rb', line 64

def session
  @session
end

Instance Method Details

#perform!TokenSet

Performs token refresh with retry logic

Returns:

  • (TokenSet)

    New token set

Raises:



78
79
80
81
82
83
84
85
86
87
# File 'lib/atproto_auth/token/refresh.rb', line 78

def perform!
  synchronize do
    raise RefreshError.new("No refresh token available", retry_possible: false) unless session.renewable?
    raise RefreshError.new("No access token to refresh", retry_possible: false) if session.tokens.nil?

    with_retries do
      request_token_refresh
    end
  end
end