JSON Web Key (JWK)

Changed in version v0.15: This documentation is updated for v0.15. Please check “v0.14” documentation for Authlib v0.14.

A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. An example would help a lot:

{
  "kty": "EC",
  "crv": "P-256",
  "x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
  "y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0",
  "kid": "iss-a"
}

This is an Elliptic Curve Public Key represented by JSON data structure. JsonWebKey.import_key() will convert PEM, JSON, bytes into these keys:

  1. OctKey
  2. RSAKey
  3. ECKey
  4. OKPKey

Algorithms for kty (Key Type) is defined by RFC7518: JSON Web Algorithms. Import a key with:

from authlib.jose import JsonWebKey

key_data = read_file('public.pem')
key = JsonWebKey.import_key(key_data, {'kty': 'RSA'})

key.as_dict()
key.as_json()

You may pass extra parameters into import_key method, available parameters can be found on RFC7517 Section 4.