Skip to content

Authentication and Permissions

Dan Melton edited this page May 1, 2019 · 2 revisions

User Roles

There are three roles in the system. Government Admin, Campaign Admin and Campaign Staff. They are represented as government_admin, campaign_admin and campaign_staff.

Government Admin

The government admin role has the ability to add new users to a campaign of any, and additional government admins to the government entity.

Campaign Admin

The campaign admin role can add new admins or staff to a campaign.

Campaign Staff

The campaign staff role cannot add new staff to a campaign.

JWT Tokens & Sessions

The frontend and the backend use JWT Tokens to communicate user session and authorization information. You can read more about the token here: https://jwt.io

Our JWT Token is created using the following formats:

Header

{
  "alg": "HS256",
  "typ": "JWT"
}

Payload

{
  "userId": 1,
  "firstName": "John",
  "lastName" : "Doe",
  "government": {
     "id": 1,
     "name": "City of Portland",
     "role": "government_admin"
  },
  "campaigns": [
   {"id": 8,
   "name": "John for Mayor",
   "role": "campaign_admin"
   },
   {"id": 12,
   "name": "Jame for Council",
   "role": "campaign_staff"
   }   
  ]
}

Signature verification HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), your-256-bit-secret)

This produces a token like eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImZpcnN0TmFtZSI6IkpvaG4iLCJsYXN0TmFtZSI6IkRvZSIsImdvdmVybm1lbnQiOnsiaWQiOjEsIm5hbWUiOiJDaXR5IG9mIFBvcnRsYW5kIiwicm9sZSI6ImdvdmVybm1lbnRfYWRtaW4ifSwiY2FtcGFpZ25zIjpbeyJpZCI6OCwibmFtZSI6IkpvaG4gZm9yIE1heW9yIiwicm9sZSI6ImNhbXBhaWduX2FkbWluIn0seyJpZCI6MTIsIm5hbWUiOiJKYW1lIGZvciBDb3VuY2lsIiwicm9sZSI6ImNhbXBhaWduX3N0YWZmIn1dfQ.zKpy4EYiNgZocX9SnDprjbN6ZHPSXQs32lY3z2CfPjA

The token is generated by the API on a login request and passed to the frontend using cookie headers with an expiration of 72 hours. This should be stored and used as an authorization header.

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImZpcnN0TmFtZSI6IkpvaG4iLCJsYXN0TmFtZSI6IkRvZSIsImdvdmVybm1lbnQiOnsiaWQiOjEsIm5hbWUiOiJDaXR5IG9mIFBvcnRsYW5kIiwicm9sZSI6ImdvdmVybm1lbnRfYWRtaW4ifSwiY2FtcGFpZ25zIjpbeyJpZCI6OCwibmFtZSI6IkpvaG4gZm9yIE1heW9yIiwicm9sZSI6ImNhbXBhaWduX2FkbWluIn0seyJpZCI6MTIsIm5hbWUiOiJKYW1lIGZvciBDb3VuY2lsIiwicm9sZSI6ImNhbXBhaWduX3N0YWZmIn1dfQ.zKpy4EYiNgZocX9SnDprjbN6ZHPSXQs32lY3z2CfPjA

Clone this wiki locally