Sha256: ab4a09a0b29ba10a3fb6da07ae20a1750e28d958216fee117fdaa73dab1157c0

Contents?: true

Size: 1.27 KB

Versions: 31

Compression:

Stored size: 1.27 KB

Contents

module Rack
  module OAuth2
    module Server
      class Resource < Abstract::Handler
        ACCESS_TOKEN = 'rack.oauth2.access_token'
        DEFAULT_REALM = 'Protected by OAuth 2.0'
        attr_accessor :realm, :request

        def initialize(app, realm = nil, &authenticator)
          @app = app
          @realm = realm
          super(&authenticator)
        end

        def _call(env)
          if request.oauth2?
            access_token = authenticate! request.setup!
            env[ACCESS_TOKEN] = access_token
          end
          @app.call(env)
        rescue Rack::OAuth2::Server::Abstract::Error => e
          e.realm ||= realm
          e.finish
        end

        private

        def authenticate!(request)
          @authenticator.call(request)
        end

        class Request < Rack::Request
          attr_reader :access_token

          def initialize(env)
            @env = env
            @auth_header = Rack::Auth::AbstractRequest.new(env)
          end

          def setup!
            raise 'Define me!'
          end

          def oauth2?
            raise 'Define me!'
          end
        end
      end
    end
  end
end

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
rack-oauth2-1.21.3 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.21.2 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.21.1 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.21.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.20.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.19.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.18.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.17.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.16.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.15.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.14.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.13.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.13.0.beta lib/rack/oauth2/server/resource.rb
rack-oauth2-1.12.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.11.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.10.1 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.10.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.9.3 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.9.2 lib/rack/oauth2/server/resource.rb
rack-oauth2-1.9.1 lib/rack/oauth2/server/resource.rb