Module: PublishingPlatform::SSO::ControllerMethods
- Included in:
- AuthenticationsController
- Defined in:
- lib/publishing_platform_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_signed_in? ⇒ Boolean
- #warden ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 4 def self.included(base) base.rescue_from PermissionDeniedError do |e| if PublishingPlatform::SSO::Config.api_only render json: { message: e. }, status: :forbidden else render "authorisations/unauthorised", status: :forbidden, locals: { message: e. } end end unless PublishingPlatform::SSO::Config.api_only base.helper_method :user_signed_in? base.helper_method :current_user end end |
Instance Method Details
#authenticate_user! ⇒ Object
27 28 29 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 27 def authenticate_user! warden.authenticate! end |
#authorise_user!(permissions) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 19 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! PublishingPlatform::SSO::AuthoriseUser.call(current_user, ) end |
#current_user ⇒ Object
35 36 37 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 35 def current_user warden.user if user_signed_in? end |
#logout ⇒ Object
39 40 41 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 39 def logout warden.logout end |
#user_signed_in? ⇒ Boolean
31 32 33 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 31 def user_signed_in? warden && warden.authenticated? end |
#warden ⇒ Object
43 44 45 |
# File 'lib/publishing_platform_sso/controller_methods.rb', line 43 def warden request.env["warden"] end |