ExFTP.Authenticator behaviour (ExFTP v1.0.4)
View SourceA behaviour defining an Authenticator.
Authenticators are used by the FTP interface to verify login credentials.
๐ See Also
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
Summary
Types
State held onto by the server and modified by the Authenticator
.
The string value of the security challenge.
A string representing a user (e.g "jsmith"
)
Callbacks
Given the current state, whether this session is still considered authenticated
Request a login given a security challenge value.
Whether a given username is valid.
Types
@type authenticator_state() :: %{}
State held onto by the server and modified by the Authenticator
.
It may be used by the authenticator to keep stateful values.
โ ๏ธ Reminders
Special Keys
authenticated:
true
will exist if the current user has successfully calledlogin/2
during this session (and the Authenticator hasn't otherwise removed it)username:
username/0
will exist if the current session has defined the user (but hasn't necessarily supplied a password)
๐ See Also
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
@type password() :: String.t()
The string value of the security challenge.
โ ๏ธ Reminders
What is a password, really?
A password could be used in the traditional sense; but this could also be a OTP, a hash, or any string value that the user would use to authenticate
๐ See Also
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
@type username() :: String.t()
A string representing a user (e.g "jsmith"
)
๐ See Also
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
Callbacks
@callback authenticated?(authenticator_state()) :: boolean()
Given the current state, whether this session is still considered authenticated
๐ท๏ธ Params
- authenticator_state ::
authenticator_state/0
โคต๏ธ Returns
โ On Success
`true` or `false`
๐ป Examples
iex> alias ExFTP.Auth.PassthroughAuth
iex> PassthroughAuth.authenticated?(%{authenticated: true})
true
iex> PassthroughAuth.authenticated?(%{})
false
โ ๏ธ Reminders
Authenticator State
The authenticator_state/0
will contain authenticated: true
if login has succeeded before in this session.
Authenticators may choose to drop that key for their own use cases (e.g if a TTL expires)
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
@callback login(password(), authenticator_state()) :: {:ok, authenticator_state()} | {:error, term()}
Request a login given a security challenge value.
๐ท๏ธ Params
- password ::
password/0
- authenticator_state ::
authenticator_state/0
โคต๏ธ Returns
โ On Success
{:ok, authenticator_state}
โ On Failure
{:error, bad_login}
๐ป Examples
iex> alias ExFTP.Auth.PassthroughAuth
iex> {:ok, _auth_state} = PassthroughAuth.login("password", %{username: "jsmith"})
iex> {:error, _} = PassthroughAuth.login("password", %{})
iex> # "root" is a disallowed user in PassthroughAuth
iex> {:error, _} = PassthroughAuth.login("password", %{username: "root"})
โ ๏ธ Reminders
Authenticator State
The authenticator_state/0
will contain a :username
key, if one was provided.
On success, the authenticator_state will be automatically updated to include authenticated: true
.
See authenticated?/1
for more information.
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)
Whether a given username is valid.
๐ท๏ธ Params
- username ::
username/0
โคต๏ธ Returns
โ On Success
`true` or `false`
๐ป Examples
iex> alias ExFTP.Auth.PassthroughAuth
iex> PassthroughAuth.valid_user?("jsmith")
true
iex> PassthroughAuth.valid_user?("root")
false
โ ๏ธ Reminders
๐ Security
The client will never be informed that a username is invalid.
The server uses this method to short-circuit auth calls.
๐ Resources
- ๐ RFC 959 (section-4)
- ๐ RFC 3659
- ๐ฌ Contact the maintainer (he's happy to help!)