Auth.Apikey (auth v1.6.0)

Defines apikeys schema and CRUD functions

Link to this section Summary

Functions

create_api_key/1 uses the encrypt_encode/1 to create an API Key that is just two strings joined with a forwardslash ("/"). This allows us to use a single environment variable.

decode_decrypt/1 accepts a key and attempts to Base58.decode followed by AES.decrypt it. If decode or decrypt fails, return 0 (zero).

encrypt_encode/1 does exactly what it's name suggests, AES Encrypts a string of plaintext and then Base58 encodes it. We encode it using Base58 so it's human-friendly (readable).

Updates a apikey.

Link to this section Functions

Link to this function

changeset(apikey, attrs)

Link to this function

create_api_key(id)

create_api_key/1 uses the encrypt_encode/1 to create an API Key that is just two strings joined with a forwardslash ("/"). This allows us to use a single environment variable.

Link to this function

create_apikey(app)

Link to this function

decode_decrypt(key)

decode_decrypt/1 accepts a key and attempts to Base58.decode followed by AES.decrypt it. If decode or decrypt fails, return 0 (zero).

Link to this function

decrypt_api_key(key)

Link to this function

encrypt_encode(plaintext)

encrypt_encode/1 does exactly what it's name suggests, AES Encrypts a string of plaintext and then Base58 encodes it. We encode it using Base58 so it's human-friendly (readable).

Link to this function

get_apikey_by_app_id(app_id)

Link to this function

update_apikey(apikey, attrs)

Updates a apikey.

Examples

iex> update_apikey(apikey, %{field: new_value})
{:ok, %Apikey{}}

iex> update_apikey(apikey, %{field: bad_value})
{:error, %Ecto.Changeset{}}