nchan_authorize_request

The nchan_authorize_request directive is used to control access to Nchan channels based on authorization rules.

Syntaxnchan_authorize_request string;
Defaultnone
Contextserver, location, if in location
Arguments1

Description

The nchan_authorize_request directive provides the capability to impose access control on Nchan pub/sub channels. It allows for tailoring authorization logic through a specified handler that determines whether a client request should be granted access to a particular channel based on its parameters. This is particularly useful in scenarios where security and user-specific content delivery are critical, as it enables the server to check user credentials or roles before allowing subscriptions or publishing actions on channels.

When configured, this directive requires a single argument which effectively points to a location or a function that processes the authorization logic. The authorization handler can evaluate incoming requests and decide if they have the right permissions to interact with the Nchan channels. If the evaluation fails, the server can respond with an appropriate error, thereby safeguarding sensitive communication and ensuring that only authorized users can access or publish messages to the Nchan channels.

As a best practice, ensure that the function or location handling the authorization checks is efficiently implemented, as any delays can affect overall performance and user experience. Furthermore, employing logging within your authorization logic can aid in troubleshooting access issues while helping to maintain a secure environment.

Config Example

location /pubsub {
    nchan_authorize_request /auth_check;
    nchan_subscriber_channel_id channel;
}

Ensure the authorization handler does not introduce performance bottlenecks by making excessive blocking calls.

If the authorization fails, make sure to provide a user-friendly error response or handler that informs the client of the failure.

← Back to all directives