How to use Auth0 to authenticate your Phoenix API, without the headache

May 18, 2020 • ☕️ 1 min read

Web DevelopmentSoftware DevelopmentProgrammingElixirTech

Auth0 makes a lot of things easy. Social Logins, Forgot Password, Magic Links, and so on, all across devices. It’s a useful tool that removes a lot of headaches and overhead in your tech stack.

Though Auth0 is a victim of its own success. A lot of people use it, which means a lot of use cases, which means a lot of features and a pile of documentation. Which at times can be both contradictory and out of date.

As a result, I took the time to create Auth0_jwks. A small library to help everyone use Auth0’s JWK functionality to authenticate their API endpoints as painlessly as possible.

Below I’ll show you how it’s used and by the end of this you will

  1. Have created a Phoenix API server
  2. Setup an Auth0 project
  3. Created a small client to retrieve the Auth0 JWT
  4. Used that JWT to make a successful call to a protected endpoint in your API.

Well enough preamble, Let’s get started!

Prerequisites

  1. Elixir
  2. Phoenix
  3. Auth0

Getting started with Auth0

Sign up for Auth0

Clone the example app

Get the JWT token

Phoenix

Create the project

Create a user

Protect an endpoint

Run It

🧞‍ This is open source! you can find it here on Github

❤️ I only write about programming and remote work. If you follow me on Twitter I won’t waste your time.