Module: SimpleAuthSdk::API::AuthenticationEndpoints

Includes:
Mixins::HTTPProxy
Defined in:
lib/simple_auth_sdk/api/authentication_endpoints.rb

Overview

This module provides authentication endpoints. It includes methods for authenticating a user and creating a new user account.

Constant Summary collapse

DEFAULT_LOGIN_URL =
'/v1/auth/login'
DEFAULT_CREATE_USER_PATH =
'/v1/auth/create-account'

Constants included from Mixins::HTTPProxy

Mixins::HTTPProxy::BASE_DELAY, Mixins::HTTPProxy::DEFAULT_RETRIES, Mixins::HTTPProxy::MAX_ALLOWED_RETRIES, Mixins::HTTPProxy::MAX_REQUEST_RETRY_DELAY, Mixins::HTTPProxy::MAX_REQUEST_RETRY_JITTER, Mixins::HTTPProxy::MIN_REQUEST_RETRY_DELAY

Instance Attribute Summary

Attributes included from Mixins::HTTPProxy

#base_uri, #headers, #retry_count, #timeout

Instance Method Summary collapse

Methods included from Mixins::HTTPProxy

#add_headers, #call, #encode_uri, #method, #request, #request_with_retry, #retry_options, #safe_parse_json, #url

Instance Method Details

#authenticate_user(login:, password:, uri: DEFAULT_LOGIN_URL, auth_headers: {}) ⇒ Hash, String

Authenticates a user with the given credentials.

Examples:

authenticate_user(login: '[email protected]', password: 'password123')

Parameters:

  • login (String)

    The login (username or email) of the user.

  • password (String)

    The password of the user.

  • uri (String) (defaults to: DEFAULT_LOGIN_URL)

    The URI for the login endpoint (optional).

Returns:

  • (Hash, String)

    The response from the authentication request, parsed as JSON if possible.



22
23
24
# File 'lib/simple_auth_sdk/api/authentication_endpoints.rb', line 22

def authenticate_user(login:, password:, uri: DEFAULT_LOGIN_URL, auth_headers: {})
  request_with_retry(:post, uri, { login: , password: password }, auth_headers)
end

#create_user(login:, confirmed_login:, password:, confirmed_password:, uri: DEFAULT_CREATE_USER_PATH, auth_headers: {}) ⇒ Hash, String

Creates a new user account with the given credentials.

Examples:

create_user(login: '[email protected]', confirmed_login: '[email protected]', password: 'password123', confirmed_password: 'password123')

Parameters:

  • login (String)

    The login (username or email) of the new user.

  • confirmed_login (String)

    Confirmation of the login.

  • password (String)

    The password for the new user.

  • confirmed_password (String)

    Confirmation of the password.

  • uri (String) (defaults to: DEFAULT_CREATE_USER_PATH)

    The URI for the create account endpoint (optional).

Returns:

  • (Hash, String)

    The response from the create account request, parsed as JSON if possible.



37
38
39
40
41
42
43
44
45
# File 'lib/simple_auth_sdk/api/authentication_endpoints.rb', line 37

def create_user(login:, confirmed_login:, password:, confirmed_password:, uri: DEFAULT_CREATE_USER_PATH, auth_headers: {})
  body = {
    'login': ,
    'login-confirm': ,
    'password': password,
    'password-confirm': confirmed_password
  }
  request_with_retry(:post, uri, body, auth_headers)
end