Class: SSO::Server::Middleware::PassportDestruction

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

Instance Method Summary collapse

Methods included from Logging

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

Constructor Details

#initialize(app) ⇒ PassportDestruction

Returns a new instance of PassportDestruction.



7
8
9
# File 'lib/sso/server/middleware/passport_destruction.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sso/server/middleware/passport_destruction.rb', line 11

def call(env)
  request = Rack::Request.new(env)

  if !(request.delete? && request.path.start_with?(passports_path))
    debug { "I'm not interested in this #{request.request_method.inspect} request to #{request.path.inspect} I only care for DELETE #{passports_path.inspect}" }
    return @app.call(env)
  end

  passport_id = request.path.to_s.split('/').last
  revocation = ::SSO::Server::Passports.logout passport_id: passport_id
  env['warden'].logout

  payload = { success: true, code: revocation.code }
  debug { "Revoked Passport with ID #{passport_id.inspect}" }

  [200, { 'Content-Type' => 'application/json' }, [payload.to_json]]
end

#json_code(code) ⇒ Object



29
30
31
# File 'lib/sso/server/middleware/passport_destruction.rb', line 29

def json_code(code)
  [200, { 'Content-Type' => 'application/json' }, [{ success: true, code: code }.to_json]]
end

#passports_pathObject



33
34
35
# File 'lib/sso/server/middleware/passport_destruction.rb', line 33

def passports_path
  OmniAuth::Strategies::SSO.passports_path
end