File: authorize.rb

package info (click to toggle)
ruby-rack-oauth2 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 564 kB
  • sloc: ruby: 4,038; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,048 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Rack
  module OAuth2
    module Server
      module Rails
        class Authorize < Server::Authorize
          def initialize(app)
            super()
            @app = app
          end

          def _call(env)
            prepare_oauth_env env
            @app.call env
          rescue Rack::OAuth2::Server::Abstract::Error => e
            e.finish
          end

          private

          def prepare_oauth_env(env)
            response_type = response_type_for(
              Server::Authorize::Request.new(env)
            ).new
            response_type._call(env)
            response_type.response.extend ResponseExt
            env[REQUEST]  = response_type.request
            env[RESPONSE] = response_type.response
          rescue Rack::OAuth2::Server::Abstract::Error => e
            env[ERROR] = e
          end

          module ResponseExt
            include Rails::ResponseExt

            def approve!
              super
              finish
            end
          end
        end
      end
    end
  end
end