stark_bank v1.1.3 StarkBank.Auth View Source

Used to manage credentials and to create a new session (login) with the StarkBank API

Functions:

  • login
  • update_access_token
  • insert_external_access_token
  • logout
  • get_env
  • get_workspace
  • get_email
  • get_access_token
  • get_member_id
  • get_workspace_id
  • get_name
  • get_permissions
  • get_auto_refresh

Link to this section Summary

Functions

Gets the access_token saved in the credentials agent after login

Gets the auto_refresh setting saved in the credentials agent after login

Gets the email saved in the credentials agent

Gets the environment saved in the credentials agent

Gets the member_id saved in the credentials agent after login

Gets the member name saved in the credentials agent after login

Gets the user permissions saved in the credentials agent after login

Gets the workspace saved in the credentials agent

Gets the workspace_id saved in the credentials agent after login

Inserts an external access-token into the current credentials agent. This is used mostly along with {auto_refresh: false} when managing multiple workers that are using the same session.

Creates a new access-token and invalidates all others

Deletes current session and invalidates current access-token

Recicles the access-token present in the credentials agent

Link to this section Functions

Link to this function

get_access_token(credentials)

View Source

Gets the access_token saved in the credentials agent after login

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • access_token [string]

Examples

iex> StarkBank.Auth.get_access_token(credentials)
"507837650305024057114529712046081608a18e96724397ad149ab182785568cddee9381a714acc903d9e0a5d17ef71"
Link to this function

get_auto_refresh(credentials)

View Source

Gets the auto_refresh setting saved in the credentials agent after login

Parameters:

  • credentials: credentials returned by Auth.login [PID]

Returns:

  • auto_refresh [boolean]

Examples

iex> StarkBank.Auth.get_permissions(credentials)
["admin"]

Gets the email saved in the credentials agent

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • email [string]

Examples

iex> StarkBank.Auth.get_email(credentials)
"user@email.com"

Gets the environment saved in the credentials agent

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • environment [:sandbox or :production]

Examples

iex> StarkBank.Auth.get_env(credentials)
:sandbox
Link to this function

get_member_id(credentials)

View Source

Gets the member_id saved in the credentials agent after login

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • password [string]

Examples

iex> StarkBank.Auth.get_member_id(credentials)
"5711452971204608"

Gets the member name saved in the credentials agent after login

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • name [string]

Examples

iex> StarkBank.Auth.get_name(credentials)
"Arya Stark"
Link to this function

get_permissions(credentials)

View Source

Gets the user permissions saved in the credentials agent after login

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • permissions [list of string]

Examples

iex> StarkBank.Auth.get_permissions(credentials)
["admin"]
Link to this function

get_workspace(credentials)

View Source

Gets the workspace saved in the credentials agent

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • workspace [string]

Examples

iex> StarkBank.Auth.get_workspace(credentials)
"workspace"
Link to this function

get_workspace_id(credentials)

View Source

Gets the workspace_id saved in the credentials agent after login

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns:

  • workspace_id [string]

Examples

iex> StarkBank.Auth.get_workspace_id(credentials)
"5078376503050240"
""
Link to this function

insert_external_access_token(credentials, access_token)

View Source

Inserts an external access-token into the current credentials agent. This is used mostly along with {auto_refresh: false} when managing multiple workers that are using the same session.

Parameters:

  • credentials [PID]: credentials returned by Auth.login
  • access_token [string]: access_token that should be used by this worker

Examples

iex> StarkBank.Auth.update_access_token(credentials, "50783765030502405711452971204608ac4d4a86e5934c858afb3e493bd3424457566319ae5244629854d36e76649f13")
Link to this function

login(env, workspace, email, password, options \\ [])

View Source

Creates a new access-token and invalidates all others

Parameters:

  • env [atom]: :sandbox, :production
  • workspace [string]: workspace name
  • email [string]: email
  • password [string]: password
  • options [keyword list]: refines request

    • access_token [string, default nil]: if nil, a new access_token will be requested from the API, else, it will be saved for further use without making any requests
    • auto_refresh [bool, default true]: if true, any credentials errors returned by the API will be responded with one attempt to retrieve a new access_token and remake the request;

Returns {:ok, credentials}:

  • credentials: PID of agent that holds the credentials information, including the access-token. This PID must be passed as parameter to all SDK calls

Examples

iex> StarkBank.Auth.login(:sandbox, "workspace", "user@email.com", "password")
{:ok, #PID<0.178.0>}

Deletes current session and invalidates current access-token

Parameters:

  • credentials [PID]: agent PID returned by StarkBank.Auth.login;

Returns:

  • parsed API response json

Examples

iex> StarkBank.Auth.logout(credentials)
{:ok, %{"message" => "Your session has been successfully closed"}}
Link to this function

update_access_token(credentials)

View Source

Recicles the access-token present in the credentials agent

Parameters:

  • credentials [PID]: credentials returned by Auth.login

Returns {:ok, credentials}:

  • credentials: PID of agent that holds the credentials information, including the access-token. This PID must be passed as parameter to all SDK calls

Examples

iex> StarkBank.Auth.update_access_token(credentials)
{:ok, #PID<0.190.0>}