pgjwt

PostgreSQL implementation of JWT (JSON Web Tokens)

  • 所有者: michelp/pgjwt
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者michelp/pgjwt
主编程语言PLpgSQL
编程语言PLpgSQL (语言数: 4)
平台
许可证MIT License
所有者活动
创建于2016-04-24 21:11:12
推送于2023-03-02 19:32:23
最后一次提交2023-03-02 11:32:22
发布数0
用户参与
星数410
关注者数23
派生数65
提交数44
已启用问题?
问题数27
打开的问题数8
拉请求数5
打开的拉请求数1
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?