Validating API Keys

We're moving along at a great pace so let's try to keep it up and implement an API key authentication mechanism so that all of our work here was not in vain! We'll use the username as the username for the user making API requests and the API key as the password for an HTTP Basic Authentication scheme. This is generally a good method for authenticating your API and will serve our purposes nicely.

We'll start off by implementing a new plug that will be responsible for handling our API key checks. We'll call this one VerifyApiKey to keep things consistent with our other custom plug. Create lib/vocial_web/verify_api_key.ex and we'll start building this out:

defmodule VocialWeb.VerifyApiKey do  def init(opts), do: opts def call(conn, ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.