Module: GDS::SSO::ControllerMethods
- Included in:
- Api::UserController, AuthenticationsController
- Defined in:
- lib/gds-sso/controller_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_user! ⇒ Object
- #authorise_user!(permissions) ⇒ Object
- #current_user ⇒ Object
- #logout ⇒ Object
- #user_remotely_signed_out? ⇒ Boolean
- #user_signed_in? ⇒ Boolean
- #warden ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gds-sso/controller_methods.rb', line 7 def self.included(base) base.rescue_from PermissionDeniedError do |e| if GDS::SSO::ApiAccess.api_call?(request.env) render json: { message: e. }, status: :forbidden else render "authorisations/unauthorised", layout: "unauthorised", status: :forbidden, locals: { message: e. } end end unless GDS::SSO::Config.api_only base.helper_method :user_signed_in? base.helper_method :current_user end end |
Instance Method Details
#authenticate_user! ⇒ Object
30 31 32 |
# File 'lib/gds-sso/controller_methods.rb', line 30 def authenticate_user! warden.authenticate! end |
#authorise_user!(permissions) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/gds-sso/controller_methods.rb', line 22 def () # Ensure that we're authenticated (and by extension that current_user is set). # Otherwise current_user might be nil, and we'd error out authenticate_user! GDS::SSO::AuthoriseUser.call(current_user, ) end |
#current_user ⇒ Object
42 43 44 |
# File 'lib/gds-sso/controller_methods.rb', line 42 def current_user warden.user if user_signed_in? end |
#logout ⇒ Object
46 47 48 |
# File 'lib/gds-sso/controller_methods.rb', line 46 def logout warden.logout end |
#user_remotely_signed_out? ⇒ Boolean
34 35 36 |
# File 'lib/gds-sso/controller_methods.rb', line 34 def user_remotely_signed_out? warden && warden.authenticated? && warden.user.remotely_signed_out? end |
#user_signed_in? ⇒ Boolean
38 39 40 |
# File 'lib/gds-sso/controller_methods.rb', line 38 def user_signed_in? warden && warden.authenticated? && !warden.user.remotely_signed_out? end |
#warden ⇒ Object
50 51 52 |
# File 'lib/gds-sso/controller_methods.rb', line 50 def warden request.env["warden"] end |