Class: Conexa::Auth

Inherits:
ConexaObject show all
Defined in:
lib/conexa/resources/auth.rb

Overview

Note:

For most cases, use Application Token instead (configured in Conexa.configure)

Authentication resource for username/password authentication

Examples:

Authenticate with credentials

auth = Conexa::Auth.(username: 'admin', password: 'secret')
auth.access_token  # => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
auth.expires_in    # => 28800

Constant Summary

Constants inherited from ConexaObject

ConexaObject::RESOURCES

Instance Attribute Summary

Attributes inherited from ConexaObject

#attributes

Class Method Summary collapse

Methods inherited from ConexaObject

#==, #[]=, convert, #empty?, #initialize, #respond_to_missing?, #to_hash, #unsaved_attributes

Constructor Details

This class inherits a constructor from Conexa::ConexaObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Conexa::ConexaObject

Class Method Details

.login(username:, password:) ⇒ Auth Also known as: authenticate

Authenticate with username and password

Examples:

auth = Conexa::Auth.(username: 'admin', password: 'mypassword')
# Use the token for subsequent requests
Conexa.configure { |c| c.api_token = auth.access_token }

Parameters:

  • username (String)

    Login username (admin or employee email)

  • password (String)

    Password

Returns:

  • (Auth)

    Authentication result with access_token

Raises:

  • (Conexa::AuthenticationError)

    if credentials are invalid



25
26
27
28
29
30
# File 'lib/conexa/resources/auth.rb', line 25

def (username:, password:)
  Conexa::Request.auth('/auth', params: {
    username: username,
    password: password
  }).call('auth')
end