Sha256: 69788dd9c23f68af01c1c2f1ea4371fd9bf7bb17df53f3141779d1d308c83704

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module GDS
  module SSO
    module ControllerMethods
      class PermissionDeniedException < StandardError
      end

      def authorise_user!(scope, permission)
        if not current_user.has_permission?(scope, permission)
          raise PermissionDeniedException
        end
      end

      def require_signin_permission!
        authorise_user!(GDS::SSO::Config.default_scope, 'signin')
      rescue PermissionDeniedException
        headers["X-Slimmer-Skip"] = "1" # If slimmer used, without this you would see a generic 400 error page
        render "authorisations/cant_signin", layout: "unauthorised", status: :forbidden
      end

      def authenticate_user!
        warden.authenticate!
      end

      def user_signed_in?
        warden.authenticated?
      end

      def current_user
        warden.user if user_signed_in?
      end

      def log_out
        warden.log_out
      end

      def warden
        request.env['warden']
      end

      def self.included(base)
        base.helper_method :user_signed_in?
        base.helper_method :current_user
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gds-sso-0.7.7 lib/gds-sso/controller_methods.rb
gds-sso-0.7.6 lib/gds-sso/controller_methods.rb
gds-sso-0.7.5 lib/gds-sso/controller_methods.rb
gds-sso-0.7.4 lib/gds-sso/controller_methods.rb