class SSO::Server::Doorkeeper::GrantMarker

Attributes

response[R]

Public Class Methods

new(app) click to toggle source
# File lib/sso/server/doorkeeper/grant_marker.rb, line 10
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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
code() click to toggle source
# File lib/sso/server/doorkeeper/grant_marker.rb, line 38
def code
  response.first
end
location_header() click to toggle source
# 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_token() click to toggle source
# 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_id() click to toggle source
# File lib/sso/server/doorkeeper/grant_marker.rb, line 46
def passport_id
  session['passport_id']
end
redirect_uri() click to toggle source
# 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_params() click to toggle source
# 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
request() click to toggle source
# File lib/sso/server/doorkeeper/grant_marker.rb, line 34
def request
  ::ActionDispatch::Request.new @env
end
warden() click to toggle source
# File lib/sso/server/doorkeeper/grant_marker.rb, line 42
def warden
  request.env['warden']
end