# Authz Keycloak Configuration

The `authz-keycloak` plugin delegates UMA permission decisions to Keycloak Authorization Services for APISIX and API7 Gateway requests.<!-- --> <!-- -->Configuration covers plugin parameters.

## Parameters[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

This plugin supports gateway references in string-valued configuration fields. Use the `$env://` prefix for environment variables or the `$secret://` prefix for values from a secret manager, such as HashiCorp Vault’s [KV secrets engine](https://developer.hashicorp.com/vault/docs/secrets/kv). The gateway resolves these references at runtime. ADC `${NAME}` interpolation is different because ADC resolves it while loading the configuration file, before synchronization. For more information, see [environment variables in plugin](https://docs.api7.ai/apisix/reference/environment-variables.md#plugins) and [secrets](https://docs.api7.ai/apisix/key-concepts/secrets.md).

* client\_id

  string

  required

  ***

  Client ID.

* client\_secret

  string

  ***

  Client secret used when the plugin authenticates to the token endpoint. When field encryption is enabled and configuration is stored in etcd, the gateway encrypts this value before storage.

* discovery

  string

  ***

  URL to the discovery document. At least one of `discovery` and `token_endpoint` is required.

* token\_endpoint

  string

  ***

  Token endpoint that supports the `urn:ietf:params:oauth:grant-type:uma-ticket` grant type for permission evaluation. If provided, it overrides the value from the discovery document. At least one of `discovery` and `token_endpoint` is required.

* resource\_registration\_endpoint

  string

  ***

  A UMA-compliant resource registration endpoint. When `lazy_load_paths` is `true`, the plugin uses this value first and otherwise obtains the endpoint from the discovery document. Dynamic path loading requires `discovery`, or both `token_endpoint` and `resource_registration_endpoint`.

* grant\_type

  string

  default: `urn:ietf:params:oauth:grant-type:uma-ticket`

  valid value:

  urn:ietf:params:oauth:grant-type:uma-ticket

  ***

  UMA ticket grant used for permission evaluation. This is the default and only accepted value.

* policy\_enforcement\_mode

  string

  default: `ENFORCING`

  valid value:

  `ENFORCING` or `PERMISSIVE`

  ***

  Controls how the plugin handles an empty permission list before it requests a decision from Keycloak.

  In `ENFORCING` mode, an empty permission list returns `403 Forbidden`, or `307 Temporary Redirect` when `access_denied_redirect_uri` is configured.

  In `PERMISSIVE` mode, the plugin continues to the UMA token request without a permission parameter. Keycloak still determines whether the request is authorized.

* permissions

  array\[string]

  default: `[]`

  ***

  Permissions representing the resources and scopes the client is seeking access to. Supported forms are `RESOURCE_ID#SCOPE_ID`, `RESOURCE_ID`, and `#SCOPE_ID`. Several scopes of one resource are separated by commas, for example `RESOURCE_ID#SCOPE_1,SCOPE_2`. Used when `lazy_load_paths` is `false`. See [obtaining permissions](https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_obtaining_permissions).

  Keycloak must grant every configured permission and every scope within each permission. Spaces around scope names are ignored. APISIX 3.20.0 and API7 Enterprise 3.9.23 and 3.10.9 enforce this requirement. Earlier versions forwarded the request when any one of the requested permissions was granted.

* lazy\_load\_paths

  boolean

  default: `false`

  ***

  If `true`, dynamically resolve the request URI to Keycloak resources through the resource registration endpoint. See [lazy load paths](https://www.keycloak.org/docs/latest/authorization_services/index.html#_enforcer_configuration).

  Dynamic loading requires the plugin to obtain a service-account access token. Enable **Service account roles** for the Keycloak client and ensure the token contains the `uma_protection` role before using the [Protection API](https://www.keycloak.org/docs/latest/authorization_services/index.html#authorization-services).

* http\_method\_as\_scope

  boolean

  default: `false`

  ***

  If `true`, use the request's HTTP method as an authorization scope.

  When `lazy_load_paths` is `false`, the plugin adds the method scope to every static permission in `permissions`, including permissions that already specify scopes.

  Keycloak must grant the HTTP method scope in addition to every scope configured for the permission. This behavior was introduced in APISIX 3.20.0 and API7 Enterprise 3.9.23 and 3.10.9.

* timeout

  integer

  default: `3000`

  valid value:

  greater than or equal to 1000

  ***

  Timeout in milliseconds for the HTTP connection with the identity provider.

* access\_token\_expires\_in

  integer

  default: `300`

  valid value:

  greater than or equal to 1

  ***

  Lifetime of the access token in seconds if no `expires_in` attribute is present in the token endpoint response.

* access\_token\_expires\_leeway

  integer

  valid value:

  greater than or equal to 0

  ***

  Expiration leeway in seconds for access token renewal. When set to a value greater than 0, token renewal will take place the set amount of time before token expiration. This avoids errors in case the access token just expires when arriving to the resource server.

* refresh\_token\_expires\_in

  integer

  default: `3600`

  valid value:

  greater than 0

  ***

  Expiration time of the refresh token in seconds.

* refresh\_token\_expires\_leeway

  integer

  valid value:

  greater than or equal to 0

  ***

  Expiration leeway in seconds for refresh token renewal. When set to a value greater than 0, token renewal will take place the set amount of time before token expiration. This avoids errors in case the access token just expires when arriving to the resource server.

* ssl\_verify

  boolean

  default: `true`

  ***

  If true, verify the OpenID provider's SSL certificates.

* cache\_ttl\_seconds

  integer

  default: `86400`

  valid value:

  greater than 0

  ***

  TTL in seconds for the plugin to cache discovery document and access tokens.

* keepalive

  boolean

  default: `true`

  ***

  If `true`, keep HTTP connections to the identity provider open for reuse.

* keepalive\_timeout

  integer

  default: `60000`

  valid value:

  greater than or equal to 1000

  ***

  Idle time in milliseconds after which an established HTTP connection is closed.

* keepalive\_pool

  integer

  default: `5`

  valid value:

  greater than or equal to 1

  ***

  Maximum number of connections in the connection pool.

* access\_denied\_redirect\_uri

  string

  ***

  URI used for a `307 Temporary Redirect` when the permission list is empty in `ENFORCING` mode or Keycloak returns `403 Forbidden`.

* password\_grant\_token\_generation\_incoming\_uri

  string

  ***

  Legacy compatibility option that exposes an endpoint for the OAuth Resource Owner Password Credentials grant. When a form-encoded `POST` containing `username` and `password` matches this URI, the plugin submits a password-grant request to the configured `token_endpoint` and returns its response. OAuth 2.0 Security Best Current Practice states that this grant must not be used. Do not configure this field for new deployments. See [RFC 9700, section 2.4](https://www.rfc-editor.org/rfc/rfc9700.html#section-2.4).

* max\_req\_body\_size

  integer

  default: `67108864`

  valid value:

  greater than or equal to 1

  ***

  Maximum request body size in bytes buffered into memory when the plugin generates a password-grant token. If the body exceeds the limit or cannot be read, the plugin returns `503 Service Unavailable`. Available in API7 Enterprise 3.9.17 and 3.10.4, and in APISIX 3.18.0.
