Sha256: a56d83b326320cb1a81f56823ded188b9dc2ac9a14798e2188c27d86a142b3be

Contents?: true

Size: 743 Bytes

Versions: 4

Compression:

Stored size: 743 Bytes

Contents

module Workarea
  module Api
    module Storefront
      module Authentication
        extend ActiveSupport::Concern

        class InvalidError < RuntimeError; end

        included do
          helper_method :current_user
        end

        def current_user
          return @current_user if defined?(@current_user)

          user = authenticate_with_http_token do |token, options|
            User::AuthenticationToken.authenticate(token, options).try(:user)
          end

          @current_user = user || raise(InvalidError)
        end

        def authentication?
          regex = ActionController::HttpAuthentication::Token::TOKEN_REGEX
          request.authorization.to_s[regex].present?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
workarea-api-4.4.7 storefront/app/controllers/workarea/api/storefront/authentication.rb
workarea-api-storefront-4.4.7 app/controllers/workarea/api/storefront/authentication.rb
workarea-api-4.4.6 storefront/app/controllers/workarea/api/storefront/authentication.rb
workarea-api-storefront-4.4.6 app/controllers/workarea/api/storefront/authentication.rb