Code Monkey home page Code Monkey logo

teal-finance / quid Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 2.0 7.28 MB

Refresh/Access JWT authentication server with backend + administration frontend supporting HMAC (HS256 HS384 HS512), RSA (RS256 RS384 RS512), ECDSA (ES256 ES384 ES512) and Ed25519 (EdDSA). See also other repos for Javascript, Python and Go client libraries.

License: MIT License

Go 49.49% JavaScript 1.42% HTML 0.60% Vue 24.38% Procfile 0.01% TypeScript 19.45% CSS 0.04% Makefile 2.90% Dockerfile 1.55% Shell 0.17%
golang jwt-authentication access-token ecdsa-signature eddsa es256 es384 es512 hmac-sha256 hmac-signature

quid's Introduction

❄ Quid       Go Reference Go Report Card

Quid preview

Quid is a JWT server (frontend + backend + client libraries) to manage Administrators, Users, Refresh Tokens and Access Tokens in independent Namespaces providing signature verification for the following algorithms:

  • HS256 = HMAC using SHA-256
  • HS384 = HMAC using SHA-384
  • HS512 = HMAC using SHA-512
  • RS256 = RSASSA-PKCS1-v1_5 using 2048-bits RSA key and SHA-256
  • RS384 = RSASSA-PKCS1-v1_5 using 2048-bits RSA key and SHA-384
  • RS512 = RSASSA-PKCS1-v1_5 using 2048-bits RSA key and SHA-512
  • ES256 = ECDSA using P-256 and SHA-256
  • ES384 = ECDSA using P-384 and SHA-384
  • ES512 = ECDSA using P-521 and SHA-512
  • EdDSA = Ed25519

Authentication flow chart

  1. First, the user logs in with Namespace + Username + Password. The Namespace is usually the final application name, represented by Application API at the bottom of the previous diagram.

  2. Then, the client (e.g. JS code) receives a Refresh Token that is usually valid for a few hours to avoid to log again during the working session.

  3. The client sends this Refresh Token to get an Access Token that is valid for a short time, usually a few minutes, say 10 minutes. So the client must refresh its Access Token every 10 minutes.

  4. During these 10 minutes, the client can request the Application API with the same Access Token.

  5. When the Application API receives a request from the client, it checks the JWT signature and expiration time. The Access Token is stateless: the Application API does not need to store any information about the user (the Access Token content is enough).

Install

Download the latest release to run a binary or clone the repository to compile from source. See also the Dockerfile to run Quid within a light container (less than 20 MB).

Build from source

make all -j

Configure

  1. Create the default config file:

     ./quid -conf
    
  2. Create the quid database: instructions

  3. Edit the configuration file to set your PostgreSQL credentials:

     vim config.json
    
  4. Initialize the quid database and create the administrator user:

     ./quid -init
    

    These registered administrator username and password will be required to login the Administration UI.

Run the backend

./quid

or simply:

go run ./cmd/quid -dev

See also: run in dev mode

Quid serves the static web site. Open http://localhost:8090 to login into the admin interface:

xdg-open http://localhost:8090

Screenshot

Deploy on Heroku

Deploy

Request tokens

Request a refresh token and use it to request access tokens.

Refresh token

A public endpoint is available to request refresh tokens for namespaces. A time to live must be provided.

Example: request a refresh token with a 10 minutes lifetime /token/refresh/10m

curl localhost:8090/token/refresh/10m          \
     -H 'Content-Type: application/json'       \
     -d '{"namespace":"my_namespace","username":"my_username","password":"my_password"}'

Response:

{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IzpXVCJ9..." }

Access token

A public endpoint is available to request access tokens for namespaces. A time to live must be provided.

Example: request an access token with a 10 minutes lifetime /token/access/10m

curl localhost:8090/token/access/10m           \
     -H 'Content-Type: application/json'                      \
     -d '{"namespace":"my_namespace","refresh_token":"zpXVCJ9..."}'

Response:

{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IzpXVCJ9..." }

Note: if the requested duration exceeds the max authorized tokens time to live for the namespace the demand will be rejected

Decode tokens

Python

import jwt

try:
    payload = jwt.decode(token, key, algorithms=['HS256'])
except jwt.ExpiredSignatureError:
    # ...

Payload example:

{
  "usr": "jane",
  "grp": ["group1", "group2"],
  "org": ["organization1", "organization2"],
  "exp": 1595950745
}

Note: "exp" is the expiration timestamp in Unix time format (seconds since 1970).

Examples

See the examples for various backends.

Client libraries

Client libraries transparently manage the requests to api servers. If a server returns a 401 Unauthorized response when an access token is expired, the client library will request a new access token from a Quid server, using a refresh token, and will retry the request with the new access token.

Javascript

QuidJS : the javascript requests library.

WebAuthn and FIDO2 features

Quid does not support WebAuthn and FIDO2. See the following open-source projects providing these features:

Other Go and JWT related projects:

quid's People

Contributors

0uep avatar dependabot[bot] avatar kahlys avatar micheartin avatar olibre avatar synw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

quid's Issues

Store namespace information within the refresh token

To generate a new refresh_token we provide three values:

  • namespace
  • username
  • password

To request a new access_token we currently must provide the already known namespace:

curl -X POST http://localhost:8082/token/access/10m           \
     -H 'Content-Type: application/json'                      \
     -d '{"refresh_token":"zpXVCJ9...", "namespace":"my_namespace"}'

If we store the namespace information within the refresh_token, we can simplify the access_token request:

curl -X POST http://localhost:8082/token/access/10m           \
     -H 'Content-Type: application/json'                      \
     -d '{"refresh_token":"zpXVCJ9..."}'

GRPC API

Would you accept a GRPC API ?

I need to access quid from various languages and so GPRC makes that easy from flutter, golang and rust.

The existing API can live along side a GRPC, so it wont break the current node based admin gui.


I was actually thinking of making a Admin GUI using flutter web, just easier to manage and extend i find. I guess you however hoe vuejs for a reason and so dont want a PR for this ?

anyway, let me know...

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.