To start your Phoenix app:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.create && mix ecto.migrate
- Start Phoenix endpoint with
mix phoenix.server
Now you can visit localhost:4000
from your browser.
Create the sample app:
mix phoenix.new jwt_phoenix --no-brunch --no-html
You need to export appropriate variables required for auth0 configuration. You can check config.exs to see that following environment variables are being used.
#!/bin/bash
export AUTH0_BASEURL="https://<app>.auth0.com/"
export AUTH0_APP_ID="<APP_ID>"
export AUTH0_APP_SECRET="<APP_SECRET>"
mix phoenix.server
Now, you can send curl requests:
curl http://localhost:4000/api/status # gives 401
curl -H "Authorization: Bearer <valid_jwt_token>" http://localhost:4000/api/status # gives 200
# when the token does not have app_metadata containing role admin
curl -H "Authorization: Bearer <jwt_token>" http://localhost:4000/api/admin # gives 403
curl -H "Authorization: Bearer <appropriate_jwt_token>" http://localhost:4000/api/admin # gives 200