Coder Social home page Coder Social logo

peas's Introduction

Postgres. Elm. Authentication. Servant (P.E.A.S)

This project demonstrates a fullstack application.

Building

This project uses the Nix package manager:

$ nix-shell
$ sh make.sh

nix-shell will enter into an isolated environment which contains:

  • Haskell tool chain with required packages, and some dev tools (Haskell Language Server)
  • Postgres database programs.
  • Elm compiler.

sh make.sh will

  • setup the database with test data and start it.
  • build the Haskell backend.
  • generate the Elm types from Haskell types.
  • compile the Elm fronted.
  • run the server on http://localhost:8081 which responds to page and endpoint requests

Authentication

JSON Web Token (JWT)

JSON Web Token (JWT) is a flexible format of a token which allows for different authentication capabilities based on how the JWT is constructed and used.

The wikipedia page provides a nice description:

In a rough summary:

  • The general use case is to be able to verfy that data in the payload of the JWT did indeed get constructed by the expected and trusted JWT issuers.

    • For example the payload can contain the claim that "bob is an admin".
    • And we want to verify this claim came from the expected issuer by using the signature of the JWT, and not from an imposter.
  • JWT consists of a header, payload, and signature.

    • header: Contains JSON information that conforms to the JWT spec e.g identifies the algorithm used to generate the signature.
    • payload: Can essentially contain any data the user wants in the form of JSON, though there exist standard fields.
    • signature:
      • The signature can be constructued with just a private key or a private/public key combo.
      • The signature is of the header concatenated with the payload.
      • The point of the signature it to able to be able to tell with either the public or private key, that it was indeed signed by the expected private key.

Authentication in this App

  • In this app the user will receive a JWT upon proving that they are who they say they are i.e providing a username and password (sent over HTTPS).
  • The server will construct the JWT and its signature with its private key and then send it to the client.
  • The client then will uses this token to access the private endpoints.
  • The server will simply verify that the JWT was signed by its own private key.

This however means that if an attacker compromises this JWT, then the attacker can simply use it to query the private endpoints. So the authentication system relies that the JWT is kept securely by the client.

Hence this relies on the trust of:

  • The browser. Must ensure browsers javascript runtime/storage is sandboxed and there is no ways of leaking the token outside of the context of the webpage and webserver.
  • The transimission mechanism. Must ensure HTTPS.
  • The client user. Must trust that the user doesn't want to simply send the token to someone else.
  • The initial form of verification. i.e in this case the username and password process must be secure, and implemented correctly by the server.

peas's People

Contributors

ernestkz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.