Sha256: 27be1764101889d98ca6186a6f4e4dcacb19e6c64e718ab562bb3f222a18c263

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module Rack
  module OAuth2
    module Server
      class Resource
        class Bearer < Resource
          def call(env)
            self.request = Request.new(env)
            super
          end

          private

          class Request < Resource::Request
            def setup!
              tokens = [access_token_in_header, access_token_in_payload].compact
              @access_token = case Array(tokens).size
              when 1
                tokens.first
              else
                invalid_request!('Both Authorization header and payload includes access token.')
              end
              self
            end

            def oauth2?
              (access_token_in_header || access_token_in_payload).present?
            end

            def access_token_in_header
              if @auth_header.provided? && @auth_header.scheme.to_s == 'bearer'
                @auth_header.params
              else
                nil
              end
            end

            def access_token_in_payload
              params['access_token']
            end
          end
        end
      end
    end
  end
end

require 'rack/oauth2/server/resource/bearer/error'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rack-oauth2-1.0.6 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.0.5 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.0.4 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.0.3 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.0.2 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.0.1 lib/rack/oauth2/server/resource/bearer.rb