Skip to content

Instantly share code, notes, and snippets.

View fspot's full-sized avatar

Frédéric Matigot fspot

View GitHub Profile
@fspot
fspot / jwt.md
Last active December 6, 2018 14:28

How to craft authenticated tokens ?

Say you want to create a token with limited rights, for example with only access to a specific small app "myapp", and with a limited view on the data, like if you had a group "mygroup" assigned (this mechanism requires to setup permissions).

And say you want this token to expire in 10 hours, for security reasons.

The python code for crafting the token (using pyjwt library) would be:

import jwt
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fspot
fspot / bottlequeue.py
Created June 7, 2013 08:20
Example app using bottle and multiprocessing for queuing long jobs and using several workers.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Example app using bottle and multiprocessing for queuing long jobs
and using several workers.
"""
from multiprocessing import Process, Queue, cpu_count
from bottle import Bottle, run