Paozhu logoPaozhu Docs
Documentation
DEV

OAuth 2.1 & JWT

Authorization server, PKCE, refresh rotation and the Bearer filter.

Generate signing keys

terminalbash
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 \
  -out conf/oauth_rsa_private.pem
openssl pkey -in conf/oauth_rsa_private.pem -pubout \
  -out conf/oauth_rsa_public.pem

Configuration

conf/oauth.confini
[oauth]
issuer = https://www.example.com
kid = oauth-rs256-1
private_key_file = oauth_rsa_private.pem
public_key_file = oauth_rsa_public.pem
refresh_ttl = 2592000

Tables and endpoints

ItemRole
oauth_clientClients and secret hashes
oauth_codeSingle-use authorization codes
oauth_refreshRefresh tokens and family revocation
/oauth/tokenAuthorization code, refresh and client_credentials

JWTs contain 8 claims, including gty to distinguish users from machine clients. Access tokens last 900s, codes 300s and refresh tokens 2592000s by default.

Bearer filter

controller/src/oauth/oauth_userinfo.cppcpp
//@urlpath(oauth_bearerauth,oauth/userinfo)
std::string userinfo(std::shared_ptr<httppeer> peer)
{
    httppeer &client = peer->get_peer();
    // Bearer filter injected session keys, not client.val:
    // oauth_sub / oauth_client_id / oauth_scope / oauth_gty
    // plus adminid / userid for gty == "user"
}