Module: Fluence::Gateway::Auth::GatewayConnection

Extended by:
ActiveSupport::Concern
Defined in:
lib/fluence/gateway/auth/gateway_connection.rb

Overview

Concern for ActionCable::Connection::Base subclasses. Reads the X-User-Id header carried by the WebSocket upgrade request and resolves the matching record, installing it as the connection's scope-prefixed identifier.

Like GatewayAuthentication for controllers, the concern derives its identified_by attribute and its current_<scope> / current_<scope>= accessors from Configuration#scope_name (for instance current_account when user_model = 'Account').

The concern is permissive by default: current_<scope> is assigned (possibly to nil) and the upgrade proceeds. Call ClassMethods#authenticate_connection! in the class body to reject anonymous upgrade requests with reject_unauthorized_connection.

Lookup and just-in-time provisioning mirror GatewayAuthentication: Configuration#user_model and Configuration#subject_column drive the lookup, and Configuration#on_missing_user — if set — is called on a miss.

In Rails, Railtie includes this concern automatically in every ActionCable::Connection::Base subclass.

Examples:

Require authentication (most common)

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    authenticate_connection!
  end
end

Allow anonymous connections (public channels)

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    # current_<scope> is resolved automatically; nil when anonymous.
  end
end

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#connectvoid

This method returns an undefined value.

ActionCable connect callback. Resolves the gateway record and either assigns it to current_<scope> or rejects the upgrade, depending on Fluence::Gateway::Auth::GatewayConnection::ClassMethods#gateway_require_auth?.