Small secrets (tokens, API keys) kept in the platform's secure store.
:ok = MobSecureStore.put("anthropic", token)
{:ok, ^token} = MobSecureStore.get("anthropic")
:ok = MobSecureStore.delete("anthropic")
:error = MobSecureStore.get("anthropic")Where the values live depends on where the code runs (backend/0):
- Android: EncryptedSharedPreferences under an Android Keystore master
key (
MobSecureStore.Native). - iOS: the Keychain, as generic-password items readable after the
device's first unlock, never synced or backed up to another device
(
MobSecureStore.Native). - A phone whose app was built without this plugin's NIF (the plugin
was activated after the last native build, and only BEAMs were
deployed): every call is
{:error, :secure_store_unavailable}(MobSecureStore.Unavailable). The store fails closed instead of writing secrets to plain files. Rebuild withmix mob.deploy --native. - The host (development, tests): one 0600 file per key in a 0700
directory under the app's data dir (
MobSecureStore.File).
config :mob_secure_store, :backend, Module replaces the backend (a module
implementing this behaviour), e.g. a fake in a host app's tests. On a phone
MobSecureStore.File is refused even when configured.
Keys are non-empty UTF-8 strings; values are any binary. A key or value of
another shape raises ArgumentError.
Summary
Callbacks
Removes key; removing an absent key is :ok.
The value at key, or :error when there is none.
Upserts key: :ok means written, not queued (see each backend for what survives a power cut).
Functions
The backend in effect: the configured one, else the one for where the code
runs (detected once per VM). On a phone a configured MobSecureStore.File
is refused: the backend is then MobSecureStore.Unavailable.
Removes key. Removing a key that isn't there is :ok.
The value stored at key.
Stores value at key, replacing what was there. :ok means it's written.
Types
@type reason() :: :secure_store_unavailable | :no_data | {:sec, integer()} | {:jni, atom()} | File.posix() | term()
Why the store couldn't do what was asked.
Callbacks
Removes key; removing an absent key is :ok.
The value at key, or :error when there is none.
Upserts key: :ok means written, not queued (see each backend for what survives a power cut).
Functions
@spec backend() :: module()
The backend in effect: the configured one, else the one for where the code
runs (detected once per VM). On a phone a configured MobSecureStore.File
is refused: the backend is then MobSecureStore.Unavailable.
Removes key. Removing a key that isn't there is :ok.
The value stored at key.
:error when nothing is stored there; {:error, reason} when the store
itself failed (see reason/0), so a failure is never mistaken for an
absent key.
Stores value at key, replacing what was there. :ok means it's written.