Sha256: 93762ebda31746b4843b53d1a6e2adf80f109c05265dc54d316e6f69d3397673

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 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.parts.first.nil? && @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

39 entries across 39 versions & 1 rubygems

Version Path
rack-oauth2-2.2.1 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.2.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.1.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.0.1 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.0.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.0.0.rc3 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.0.0.rc2 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-2.0.0.rc1 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.21.3 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.21.2 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.21.1 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.21.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.20.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.19.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.18.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.17.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.16.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.15.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.14.0 lib/rack/oauth2/server/resource/bearer.rb
rack-oauth2-1.13.0 lib/rack/oauth2/server/resource/bearer.rb