Module: Glib::Auth::TokenAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Glib::ApiController
- Defined in:
- app/controllers/concerns/glib/auth/token_authenticatable.rb
Overview
Bearer-token authentication for machine-facing APIs. The token's storage column and the user model are app-specific, so the lookup is a template method the app's base controller implements (return the user for a valid token, nil otherwise).
Instance Method Summary collapse
-
#current_user ⇒ Object
Public to mirror the browser side, where Devise's current_user is public: glib hands policies the controller (Glib::ApplicationPolicy#controller), and host-app policies call these with an EXPLICIT receiver (
controller.current_user,delegate :user_signed_in?, to: :controller). -
#user_signed_in? ⇒ Boolean
Provided by Devise's helpers on the browser side; defined here so glib policies that delegate it to the controller work unchanged on API controllers.
Instance Method Details
#current_user ⇒ Object
Public to mirror the browser side, where Devise's current_user is public: glib
hands policies the controller (Glib::ApplicationPolicy#controller), and host-app
policies call these with an EXPLICIT receiver (controller.current_user,
delegate :user_signed_in?, to: :controller). A private current_user would raise
NoMethodError on the API line only -- the two surfaces must behave the same.
13 14 15 |
# File 'app/controllers/concerns/glib/auth/token_authenticatable.rb', line 13 def current_user @current_user end |
#user_signed_in? ⇒ Boolean
Provided by Devise's helpers on the browser side; defined here so glib policies that delegate it to the controller work unchanged on API controllers.
19 20 21 |
# File 'app/controllers/concerns/glib/auth/token_authenticatable.rb', line 19 def user_signed_in? current_user.present? end |