Sha256: 0577dc2b47dd99d9bfb933a26066f97102e8713803751e38d2c1652ad791191c

Contents?: true

Size: 1.26 KB

Versions: 35

Compression:

Stored size: 1.26 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?
            authenticate! request.setup!
            env[ACCESS_TOKEN] = request.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

35 entries across 35 versions & 1 rubygems

Version Path
rack-oauth2-0.12.2 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.12.1 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.12.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.11.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.10.1 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.10.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.10.0.alpha lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.5 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.4 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.3 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.2 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.1 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.0 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.9.0.alpha lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.7 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.6 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.5 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.4 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.3 lib/rack/oauth2/server/resource.rb
rack-oauth2-0.8.2 lib/rack/oauth2/server/resource.rb