All Projects → michelp → Pgjwt

michelp / Pgjwt

Licence: mit
PostgreSQL implementation of JWT (JSON Web Tokens)

Labels

Projects that are alternatives of or similar to Pgjwt

Subzero Starter Kit
Starter Kit and tooling for authoring GraphQL/REST API backends with subZero
Stars: ✭ 136 (-31.31%)
Mutual labels:  plpgsql
Wikipedia Mirror
🌐 Guide and tools to run a full offline mirror of Wikipedia.org with three different approaches: Nginx caching proxy, Kimix + ZIM dump, and MediaWiki/XOWA + XML dump
Stars: ✭ 160 (-19.19%)
Mutual labels:  plpgsql
Colpivot
Dynamic row to column pivotation/transpose in Postgres made simple.
Stars: ✭ 173 (-12.63%)
Mutual labels:  plpgsql
Postgresql Event Sourcing
postgresql event sourcing
Stars: ✭ 146 (-26.26%)
Mutual labels:  plpgsql
Cisl
Columnstore Indexes Scripts Library
Stars: ✭ 155 (-21.72%)
Mutual labels:  plpgsql
Docker Compose
一些基础服务的docker-compose配置文件,方便在一台新电脑上快速开始工作
Stars: ✭ 163 (-17.68%)
Mutual labels:  plpgsql
Ccap
open source and transparent cryptocurrency analysis platform
Stars: ✭ 128 (-35.35%)
Mutual labels:  plpgsql
Pagila
PostgreSQL Sample Database
Stars: ✭ 190 (-4.04%)
Mutual labels:  plpgsql
Pghero.sql
Postgres insights made easy
Stars: ✭ 155 (-21.72%)
Mutual labels:  plpgsql
Dox
A Document Database API extension for Postgres
Stars: ✭ 168 (-15.15%)
Mutual labels:  plpgsql
Opm Core
Central module of the OPM suite
Stars: ✭ 148 (-25.25%)
Mutual labels:  plpgsql
Chicago Atlas
View citywide information about health trends and take action near you to improve your own health.
Stars: ✭ 152 (-23.23%)
Mutual labels:  plpgsql
Pg rational
Precise fractional arithmetic for PostgreSQL
Stars: ✭ 168 (-15.15%)
Mutual labels:  plpgsql
Hierarchy Data Closure Table
This is a mysql and postgresql store procedure and trigger implementation of closure table in RDBMS about hierarchy data model.
Stars: ✭ 135 (-31.82%)
Mutual labels:  plpgsql
Sql Battleships
Play Battleships on PostgreSQL
Stars: ✭ 174 (-12.12%)
Mutual labels:  plpgsql
Pg jobmon
PostgreSQL extension which provides persistent logging within transactions and functions.
Stars: ✭ 128 (-35.35%)
Mutual labels:  plpgsql
Postgresdbsamples
Sample databases for postgres
Stars: ✭ 161 (-18.69%)
Mutual labels:  plpgsql
Amazon Redshift Udfs
A collection of example UDFs for Amazon Redshift.
Stars: ✭ 194 (-2.02%)
Mutual labels:  plpgsql
Postgis coordinate transform
一个在postgis中结合中国国情,批量对数据进行加偏到百度坐标,高德谷歌的火星坐标,或者逆向纠偏
Stars: ✭ 182 (-8.08%)
Mutual labels:  plpgsql
Learn Sql The Hard Way
http://sql.learncodethehardway.org/book/
Stars: ✭ 168 (-15.15%)
Mutual labels:  plpgsql

pgjwt

PostgreSQL implementation of JSON Web Tokens

Dependencies

This code requires the pgcrypto extension, included in most distribution's "postgresql-contrib" package. The tests require the pgtap extension to run.

Install

You will require sudo privledges and the postgres development libraries for your operating system in most cases. For ubuntu on postgres 9.5 for example, you can install them with:

sudo apt-get install postgresql-server-dev-9.5

Clone the repository and then run:

'make install'

This creates a new extension that can be installed with 'CREATE EXTENSION pgjwt;'

To run the tests install pgtap and run 'pg_prove test/test.sql'. Another approach is to use the docker based test runner, but running './test.sh'. This will require you have docker installed.

Usage

Create a token. The first argument must be valid json, the second argument any text:

=> select sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret');
                                                                        sign
-------------------------------------------------------------------------------------------------------------------------------------------------------
 eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

Verify a token:

=> select * from verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ', 'secret');
           header            |                       payload                       | valid
-----------------------------+-----------------------------------------------------+-------
 {"alg":"HS256","typ":"JWT"} | {"sub":"1234567890","name":"John Doe","admin":true} | t

Algorithm

sign() and verify() take an optional algorithm argument that can be 'HS256', 'HS384' or 'HS512'. The default is 'HS256':

=> select sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret', 'HS384'),

TODO

  • public/private keys when pgcrypto gets *_verify() functions

  • SET ROLE and key lookup helper functions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].