New token format for indoorequal.com

Inspired by the new format of the github tokens, I took the time to update the indoorequal.com token format.

The indoorequal.com allows people to register and create their API keys to use the indoor= vector tiles and API on their maps. It’s an elixir/phoenix framework codebase.

The previous API keys were generated using the puid elixir library. Here was the sample code to returns the key:

defmodule Indoorequalcom.ApiKeys do
  [...]
  use Puid, charset: :alphanum
  [...]

  defp generate_key() do
    generate()
  end
end

Following the github blog post, I upgraded the code to prepend the iek_ string (for indoorequal key), followed by the key, and then the checksum of the key encoded in base62 with leading zeros if needed.

defmodule Indoorequalcom.ApiKeys do
  [...]
  use Puid, charset: :alphanum
  [...]

  defp generate_key() do
    key = generate()
    checksum = key
      |> CRC.calculate(:crc_32)
      |> Base62.encode()
      |> String.pad_leading(6, "0")

    "iek_" <> key <> checksum
  end
end

I plan to notify all indoorequal.com users about this new token format. When all tokens will be updated, I’ll be able to simplify the key check and not hit the database when the checksum doesn’t match.

Have a comment? Contact me by email.