Skip to content
Branch: master
Find file History
Pull request Compare This branch is 1 commit behind v0.12.x.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Example - REST API JWT Auth

This example demonstrates REST API JWT Auth with aah framework. aah REST API JWT Auth includes authentication and route authorization via routes config.

Generic Auth can be customized in so many ways. This application implements JSON Web Token (JWT) using Generic auth scheme.

Learn more about Security design, Authentication and Authorization.

Get aah examples

git clone aah-examples

Run this example

cd aah-examples/rest-api-jwt-auth
aah run

Use a preferred REST client to make a request

Demo User Credentials

Username/Password Roles & Permissions IsLocked Roles: "employee", "manager"
Permissions: "user:read,edit:reportee"
No Roles: "employee"
Permissions: N/A
No Roles: "employee"
Permissions: N/A
Yes Roles: "employee", "manager", "admin"
Permissions: "user:read,edit,delete:reportee"

API Endpoints

GET     /                       - Shows welcome message (Anonymous access)
POST    /v1/token               - Issues JSON Web Token (JWT) for given username and password (Anonymous access)
GET     /v1/reportee/:email     - Returns user data for given email address based on authorization (Secured)

Welcome Message

Send GET request to http://localhost:8080/


{"message":"Welcome to aah framework - REST API Basic Auth Example"}

Get Access Token (JWT)

Send POST request to http://localhost:8080/v1/token

Request Body:

  "username": "",
  "password": "welcome123"


Returns access token for valid credentials.

    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzA1NzY3MzcsInVzZXJuYW1lIjoidXNlcjFAYWFoZnJhbWV3b3JrLm9yZyJ9.944bfZpGY8I4ktJzKPA6pJFjhIW53upQBlVT7xSJwPA",
    "token_type": "bearer"

Get Reportee data

Send GET request to http://localhost:8080/v1/reportee/

Pass access token via HTTP header Authorization: Bearer <access-token>


    "first_name": "West",
    "last_name": "Corner",
    "email": "",
    "is_locked": false,
    "is_expried": false,
    "roles": [

Now, try various combinations with the above demo credentials.

You can’t perform that action at this time.