Module: Fluence::Gateway::Auth::GatewayAuthentication
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/fluence/gateway/auth/gateway_authentication.rb
Overview
The scope name is captured at include time. Changing
Configuration#scope_name afterwards has no effect on
already-defined helpers.
Controller concern that reads the gateway identity headers and exposes scope-prefixed authentication helpers.
When the concern is included, five instance methods are
defined on the host controller class (via define_method),
where <scope> is Configuration#scope_name:
current_<scope>— memoised lookup of the user record.<scope>_signed_in?—truewhencurrent_<scope>is present.authenticate_<scope>!— renders401when the user is absent.authenticate_<scope>_or_service!— renders401unless the request is either signed-in or aclient_credentialsservice call (see #service_request?).authenticate_<scope>_or_redirect!— likeauthenticate_<scope>!for HTML navigation: an unauthenticatedGETtext/htmlrequest is redirected to the gateway login withreturn_to; anything else gets401. Requires a redirect-capable host (+ActionController::Base+).
The record is looked up via
model_class.find_by(subject_column => gateway_user_id). If no
record matches and Configuration#on_missing_user is set, it is
invoked for just-in-time provisioning.
In Rails, Railtie includes this concern automatically in
ActionController::API and ActionController::Base subclasses.
Constant Summary collapse
- GATEWAY_LOGOUT_PATH =
Path of the gateway logout endpoint, used by #gateway_logout_path. Only meaningful for server-rendered tenants where the gateway owns the session cookie.
'/auth/logout'- GATEWAY_LOGIN_PATH =
Path of the gateway OAuth initiation endpoint, used by
authenticate_<scope>_or_redirect!to send unauthenticated HTML navigation to login. Only meaningful for server-rendered tenants proxied through the gateway catch-all. '/auth'
Instance Method Summary collapse
-
#anonymous_request? ⇒ Boolean
True when the request carries no identity at all — the gateway forwarded it anonymously (no credential presented).
-
#authenticate_service! ⇒ void
Renders
401unless the request is aclient_credentialsservice call (see #service_request?). -
#gateway_auth ⇒ String?
Raw value of the
X-Gateway-Authheader (+'anonymous'+ or'authenticated'). -
#gateway_client_id ⇒ String?
Raw value of the
X-Client-Idheader (the Doorkeeper applicationuid). -
#gateway_login_path(return_to: nil) ⇒ String
Path of the gateway login (OAuth initiation) endpoint, optionally carrying a
return_toso the user lands back where they started. -
#gateway_logout_path ⇒ String
Path of the gateway logout endpoint.
-
#gateway_user_email ⇒ String?
Raw value of the
X-User-Emailheader. -
#gateway_user_first_name ⇒ String?
Raw value of the
X-User-First-Nameheader. -
#gateway_user_id ⇒ String?
Raw value of the
X-User-Idheader (the gateway subject). -
#gateway_user_last_name ⇒ String?
Raw value of the
X-User-Last-Nameheader. -
#gateway_user_scopes ⇒ String?
Raw value of the
X-User-Scopesheader (space-separated OAuth scopes, as emitted by Doorkeeper). -
#service_request? ⇒ Boolean
True when the request carries a client identity but no user, i.e.
Instance Method Details
#anonymous_request? ⇒ Boolean
True when the request carries no identity at all — the gateway
forwarded it anonymously (no credential presented). Derived from
the signed X-Client-Id / X-User-Id headers, not from the
informational #gateway_auth header: both identity headers are
part of the HMAC payload, so an anonymous request cannot forge
an identity.
Mutually exclusive with #service_request? and with a signed-in
user: user (+user_id+ present), service (+client_id+ present,
user_id blank), anonymous (both blank).
Only meaningful behind the HMAC middleware: without it (or with
skip_middleware enabled) absent headers also yield true.
#authenticate_service! ⇒ void
This method returns an undefined value.
Renders 401 unless the request is a client_credentials
service call (see #service_request?). Use as a before_action
on endpoints exposed exclusively to backend services.
#gateway_auth ⇒ String?
Raw value of the X-Gateway-Auth header (+'anonymous'+ or
'authenticated'). Informational only: the header is NOT part
of the HMAC payload — derive trust from the signed identity
headers instead (see #anonymous_request?).
#gateway_client_id ⇒ String?
Raw value of the X-Client-Id header (the Doorkeeper
application uid).
#gateway_login_path(return_to: nil) ⇒ String
Path of the gateway login (OAuth initiation) endpoint, optionally
carrying a return_to so the user lands back where they started.
Counterpart of #gateway_logout_path; used internally by
authenticate_<scope>_or_redirect!.
#gateway_logout_path ⇒ String
Path of the gateway logout endpoint. Only meaningful for server-rendered tenants where the gateway holds the session cookie; SPA tenants drop their token client-side and have no server-side logout to call.
#gateway_user_email ⇒ String?
Raw value of the X-User-Email header.
#gateway_user_first_name ⇒ String?
Raw value of the X-User-First-Name header.
#gateway_user_id ⇒ String?
Raw value of the X-User-Id header (the gateway subject).
#gateway_user_last_name ⇒ String?
Raw value of the X-User-Last-Name header.
#gateway_user_scopes ⇒ String?
Raw value of the X-User-Scopes header (space-separated
OAuth scopes, as emitted by Doorkeeper).
#service_request? ⇒ Boolean
True when the request carries a client identity but no user,
i.e. it was issued with a client_credentials token.