Class: SSO::Server::Doorkeeper::GrantMarker

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/sso/server/doorkeeper/grant_marker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #logger, #progname, #warn

Constructor Details

#initialize(app) ⇒ GrantMarker

Returns a new instance of GrantMarker.



10
11
12
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 10

def initialize(app)
  @app = app
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 7

def response
  @response
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 14

def call(env)
  @env = env
  @response = @app.call @env

  return response unless outgoing_grant_token

  if passport_id
    debug { %(Detected outgoing "Authorization Grant Token" #{outgoing_grant_token.inspect} of the "Authorization Code Grant" flow.) }
    debug { %(Augmenting Passport #{passport_id.inspect} with this outgoing Grant Token...) }
    registration = ::SSO::Server::Passports.register_authorization_grant passport_id: passport_id, token: outgoing_grant_token

    if registration.failure?
      warn { 'The passport could not be augmented. Destroying warden session.' }
      warden.logout
    end
  end

  response
end

#codeObject



38
39
40
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 38

def code
  response.first
end

#location_headerObject



50
51
52
53
54
55
56
57
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 50

def location_header
  unless code == 302
    # debug { "Uninteresting response, because it is not a redirect" }
    return
  end

  response.second['Location']
end

#outgoing_grant_tokenObject



73
74
75
76
77
78
79
80
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 73

def outgoing_grant_token
  unless redirect_uri_params && redirect_uri_params['code']
    # debug { "Uninteresting response, because there is no code parameter sent" }
    return
  end

  redirect_uri_params['code']
end

#passport_idObject



46
47
48
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 46

def passport_id
  session['passport_id']
end

#redirect_uriObject



59
60
61
62
63
64
65
66
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 59

def redirect_uri
  unless location_header
    # debug { "Uninteresting response, because there is no Location header" }
    return
  end

  ::URI.parse location_header
end

#redirect_uri_paramsObject



68
69
70
71
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 68

def redirect_uri_params
  return unless redirect_uri
  ::Rack::Utils.parse_query redirect_uri.query
end

#requestObject



34
35
36
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 34

def request
  ::ActionDispatch::Request.new @env
end

#wardenObject



42
43
44
# File 'lib/sso/server/doorkeeper/grant_marker.rb', line 42

def warden
  request.env['warden']
end