https://github.com/techgaun/jwt-phoenix-sample
Sample application for using JWT with Phoenix
https://github.com/techgaun/jwt-phoenix-sample
elixir json-web-token jwt phoenix-framework
Last synced: 9 months ago
JSON representation
Sample application for using JWT with Phoenix
- Host: GitHub
- URL: https://github.com/techgaun/jwt-phoenix-sample
- Owner: techgaun
- Created: 2017-03-19T02:41:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-16T02:18:19.000Z (over 8 years ago)
- Last Synced: 2025-04-12T11:58:21.534Z (about 1 year ago)
- Topics: elixir, json-web-token, jwt, phoenix-framework
- Language: JavaScript
- Size: 62.5 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JwtPhoenix
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`](http://localhost:4000) from your browser.
## Setup
Create the sample app:
```shell
mix phoenix.new jwt_phoenix --no-brunch --no-html
```
## Configuration
You need to export appropriate variables required for auth0 configuration.
You can check [config.exs](config/config.exs#L25-L32) to see that following environment variables are being used.
```shell
#!/bin/bash
export AUTH0_BASEURL="https://.auth0.com/"
export AUTH0_APP_ID=""
export AUTH0_APP_SECRET=""
mix phoenix.server
```
## Example
Now, you can send curl requests:
```shell
curl http://localhost:4000/api/status # gives 401
curl -H "Authorization: Bearer " http://localhost:4000/api/status # gives 200
# when the token does not have app_metadata containing role admin
curl -H "Authorization: Bearer " http://localhost:4000/api/admin # gives 403
curl -H "Authorization: Bearer " http://localhost:4000/api/admin # gives 200
```