Sha256: 6c95c9026c884055773f0a784bb6f94a537c3bae01ad53d26d61e8be01a9e313

Contents?: true

Size: 1 KB

Versions: 24

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module FmRest
  module V1
    module Auth
      ACCESS_TOKEN_HEADER = "X-FM-Data-Access-Token"

      # Requests a token through basic auth
      #
      # @param connection [Faraday] the auth connection to use for
      #   the request
      # @return The token if successful
      # @return `false` if authentication failed
      def request_auth_token(connection = FmRest::V1.auth_connection)
        request_auth_token!(connection)
      rescue FmRest::APIError::AccountError
        false
      end

      # Requests a token through basic auth, raising
      # `FmRest::APIError::AccountError` if auth fails
      #
      # @param (see #request_auth_token)
      # @return The token if successful
      # @raise [FmRest::APIError::AccountError] if authentication failed
      def request_auth_token!(connection = FmRest.V1.auth_connection)
        resp = connection.post(V1.session_path)
        resp.headers[ACCESS_TOKEN_HEADER] || resp.body["response"]["token"]
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
fmrest-core-0.26.2 lib/fmrest/v1/auth.rb
fmrest-core-0.26.1 lib/fmrest/v1/auth.rb
fmrest-core-0.26.1.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.26.0 lib/fmrest/v1/auth.rb
fmrest-core-0.26.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.25.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.24.0 lib/fmrest/v1/auth.rb
fmrest-core-0.24.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.23.1 lib/fmrest/v1/auth.rb
fmrest-core-0.23.0 lib/fmrest/v1/auth.rb
fmrest-core-0.22.0 lib/fmrest/v1/auth.rb
fmrest-core-0.21.0 lib/fmrest/v1/auth.rb
fmrest-core-0.21.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.20.0 lib/fmrest/v1/auth.rb
fmrest-core-0.20.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.19.0 lib/fmrest/v1/auth.rb
fmrest-core-0.19.0.rc1 lib/fmrest/v1/auth.rb
fmrest-core-0.18.0 lib/fmrest/v1/auth.rb
fmrest-core-0.18.0.rc3 lib/fmrest/v1/auth.rb
fmrest-core-0.18.0.rc2 lib/fmrest/v1/auth.rb