ExFTP.Auth.WebhookAuth (ExFTP v1.0.2)

View Source

When authenticator is ExFTP.Auth.WebhookAuth, this authenticator will call out to an HTTP endpoint that accepts two query parameters: username and/or password_hash.

โš™๏ธ Configuration

Keys

Example

  %{
    # ... ,
    authenticator: ExFTP.Auth.WebhookAuth,
    authenticator_config: %{
      login_url: "https://httpbin.dev/status/200",
      login_method: :post,
      password_hash_type: :sha256,
      authenticated_url: "https://httpbin.dev/status/200",
      authenticated_method: :post,
      authenticated_ttl_ms: 1000 * 60 * 60
    }
  }

๐Ÿ‘€ See Also

๐Ÿ“– Resources

Summary

Functions

Determines whether this session is still considered authenticated

Requests a login using a webhook.

Always returns true.

Functions

authenticated?(authenticator_state)

Determines whether this session is still considered authenticated

๐Ÿท๏ธ Params

๐Ÿง‘โ€๐Ÿณ Workflow

  • Reads the authenticator_config.
  • If the config has authenticated_url,
    • Calls it with the username(e.g http://httpbin.dev/get?username={username})
    • If the response is HTTP 200, success. Otherwise, no longer authenticated.
  • If the config does not have authenticated_url,
    • investigate the authenticator_state for authenticated: true

โคต๏ธ Returns

โœ… On Success

  `true` or `false`

๐Ÿ’ป Examples

iex> alias ExFTP.Auth.WebhookAuth
iex> Application.put_env(:ex_ftp, :authenticator, ExFTP.Auth.WebhookAuth)
iex> Application.put_env(:ex_ftp, :authenticator_config, %{
iex>  login_url: "https://httpbin.dev/status/200",
iex>  authenticated_url: "https://httpbin.dev/get",
iex>  authenticated_method: :get,
iex> })
iex> WebhookAuth.authenticated?(%{username: "jsmith"})
true

๐Ÿ‘€ See Also

login(password, authenticator_state)

@spec login(
  password :: ExFTP.Authenticator.password(),
  authenticator_state :: ExFTP.Authenticator.authenticator_state()
) :: {:ok, ExFTP.Authenticator.authenticator_state()} | {:error, term()}

Requests a login using a webhook.

๐Ÿท๏ธ Params

๐Ÿง‘โ€๐Ÿณ Workflow

  • Reads the authenticator_config.
  • Receives a password from the client (a :username key might exist in the authenticator_state)
  • Hashes the password
  • Calls the login_url (e.g http://httpbin.dev/get?username={username}&password_hash={password_hash})
  • If the response is HTTP 200, success. Otherwise, bad login.

โคต๏ธ Returns

โœ… On Success

  {:ok, authenticator_state}

โŒ On Failure

  {:error, bad_login}

๐Ÿ’ป Examples

iex> alias ExFTP.Auth.WebhookAuth
iex> Application.put_env(:ex_ftp, :authenticator, ExFTP.Auth.WebhookAuth)
iex> Application.put_env(:ex_ftp, :authenticator_config, %{
iex>  login_url: "https://httpbin.dev/status/200",
iex>  login_method: :post,
iex>  password_hash_type: :sha256
iex> })
iex> {:ok, _} = WebhookAuth.login("password123", %{username: "jsmith"})

๐Ÿ‘€ See Also

valid_user?(username)

@spec valid_user?(username :: ExFTP.Authenticator.username()) :: boolean()

Always returns true.

No performance benefit

This method is normally used to short-circuit bad login requests. The performance gain in that short-circuit is negligible for webhooks, so it's not used.