APIacAuthClientJWT

An APIac.Authenticator plug that implements the client authentication part of RFC7523 (JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants).

This method consists in sending a MACed or signed JWT in the request body to the OAuth2 token endpoint, for instance:

POST /token.oauth2 HTTP/1.1
Host: as.example.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&
code=n0esc3NRze7LTCu7iYzS6a5acc3f0ogp4&
client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3A
client-assertion-type%3Ajwt-bearer&
client_assertion=eyJhbGciOiJSUzI1NiIsImtpZCI6IjIyIn0.
eyJpc3Mi[...omitted for brevity...].
cC4hiUPo[...omitted for brevity...]

OpenID Connect further specifies the "client_secret_jwt" and "private_key_jwt" authentication methods (OpenID Connect Core 1.0 incorporating errata set 1 - 9. Client Authentication) refining RFC7523.

Installation

def deps do
  [
    {:apiac_auth_client_jwt, "~> 1.2"}
  ]
end

Example

plug APIacAuthClientJWT,
  client_callback: &MyApp.Client.config/1,
  protocol: :rfc7523,
  server_metadata_callback: &MyApp.metadata.get/0

Plug options

Client configuration

The client callback returns a map whose keys are those documented in OpenID Connect Dynamic Client Registration 1.0 incorporating errata set 1.

This includes the "client_secret" field that is used for MACed JWTs.

The "token_endpoint_auth_method" is mandatory and must be set to either "client_secret_jwt" or "private_key_jwt".

Determining allowed signature verification algorithms and keys

Signature verification algorithms:

Signature verification keys: if "token_endpoint_auth_method" is set to:

Replay protection

Replay protection can be implemented to prevent a JWT from being reused. This is mandatory when using OpenID Connect.

The :jti_register allows configuring a module that implements the JTIRegister behaviour.

The JTIRegister.ETS implementation provides with a basic implementation for single node servers.