Module: FmRest::V1::Auth

Included in:
FmRest::V1
Defined in:
lib/fmrest/v1/auth.rb

Constant Summary collapse

ACCESS_TOKEN_HEADER =
"X-FM-Data-Access-Token"

Instance Method Summary collapse

Instance Method Details

#request_auth_token(connection = FmRest::V1.auth_connection) ⇒ Object

Requests a token through basic auth

Parameters:

  • connection (Faraday) (defaults to: FmRest::V1.auth_connection)

    the auth connection to use for the request

Returns:

  • The token if successful

  • false if authentication failed



14
15
16
17
18
# File 'lib/fmrest/v1/auth.rb', line 14

def request_auth_token(connection = FmRest::V1.auth_connection)
  request_auth_token!(connection)
rescue FmRest::APIError::AccountError
  false
end

#request_auth_token!(connection = FmRest.V1.auth_connection) ⇒ Object

Requests a token through basic auth, raising FmRest::APIError::AccountError if auth fails

Parameters:

  • connection (Faraday) (defaults to: FmRest.V1.auth_connection)

    the auth connection to use for the request

Returns:

  • The token if successful

Raises:



26
27
28
29
# File 'lib/fmrest/v1/auth.rb', line 26

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