API Keys

View Source

A note on API Keys

API keys are generated using AshAuthentication.Strategy.ApiKey.GenerateApiKey. See the module docs for more information. The API key is generated using a random byte string and a prefix. The prefix is used to generate a key that is compliant with secret scanning. You can use this to set up an endpoint that will automatically revoke leaked tokens, which is an extremely powerful and useful security feature. We only store a hash of the api key. The plaintext api key is only available in api_key.__metadata__.plaintext_api_key immediately after creation.

See the guide on Github for more information.

Api key expiration/validity is otherwise up to you. The configured api_key_relationship should include those rules in the filter. For example:

has_many :valid_api_keys, MyApp.Accounts.ApiKey do
  filter expr(valid)
end

Installation

Use mix ash_authentication.add_strategy api_key to install this strategy, and modify the generated resource to suit your needs.