Class: ReactorSDK::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor_sdk/authentication.rb

Constant Summary collapse

IMS_TOKEN_URL =

Adobe IMS token endpoint — single global endpoint for all regions Read by Configuration as its default value for ims_token_url

'https://ims-na1.adobelogin.com/ims/token/v3'
REFRESH_BUFFER_SECONDS =

Refresh the token this many seconds before actual expiry. Prevents edge cases where a token expires between check and use.

300
REACTOR_SCOPE =

Required OAuth scopes for full Reactor API access

[
  'openid',
  'AdobeID',
  'read_organizations',
  'additional_info.projectedProductContext'
].join(',').freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Authentication

Returns a new instance of Authentication.

Parameters:



45
46
47
48
49
50
# File 'lib/reactor_sdk/authentication.rb', line 45

def initialize(config)
  @config       = config
  @token        = nil
  @token_expiry = nil
  @mutex        = Mutex.new
end

Instance Method Details

#access_tokenString

Returns a valid access token, fetching it on first use and refreshing it on later calls when needed.

When auto_refresh_token is false, an expired cached token raises AuthenticationError instead of silently refreshing.

Thread-safe — uses a Mutex to prevent parallel token fetches in multi-threaded environments such as Puma.

Returns:

  • (String)

    Valid Adobe IMS Bearer access token

Raises:



65
66
67
68
69
70
71
# File 'lib/reactor_sdk/authentication.rb', line 65

def access_token
  @mutex.synchronize do
    fetch_token if @token.nil?
    refresh_token_if_needed if token_expired?
    @token
  end
end