Class: FolioClient::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/folio_client/authenticator.rb

Overview

Fetch a token from the Folio API using login_params

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tokenObject



6
7
8
# File 'lib/folio_client/authenticator.rb', line 6

def self.token
  new.token
end

Instance Method Details

#tokenObject

Request an access_token



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/folio_client/authenticator.rb', line 11

def token # rubocop:disable Metrics/AbcSize
  response = FolioClient.connection.post(, FolioClient.config..to_json)

  UnexpectedResponse.call(response) unless response.success?

  # remove legacy_auth once new tokens enabled on Poppy
  if FolioClient.config.legacy_auth
    JSON.parse(response.body)['okapiToken']
  else
    access_cookie = FolioClient.cookie_jar.cookies.find { |cookie| cookie.name == 'folioAccessToken' }

    raise StandardError, "Problem with folioAccessToken cookie: #{response.headers}, #{response.body}" unless access_cookie

    access_cookie.value
  end
end