Class: GoogleSpreadsheetFetcher::Authorizer::Oauth2::RackApplication

Inherits:
Object
  • Object
show all
Defined in:
lib/google_spreadsheet_fetcher/authorizer/oauth2/rack_application.rb

Constant Summary collapse

AUTHORIZE_PATH =
'/authorize'.freeze
CALLBACK_PATH =
'/oauth2callback'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ RackApplication

Returns a new instance of RackApplication.



10
11
12
13
14
15
# File 'lib/google_spreadsheet_fetcher/authorizer/oauth2/rack_application.rb', line 10

def initialize(config: nil)
  @config = config || ::GoogleSpreadsheetFetcher::Authorizer::Oauth2::Config.new
  @authorizer = ::GoogleSpreadsheetFetcher::Authorizer::Oauth2::Authorizer.new(config: config)

  freeze
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/google_spreadsheet_fetcher/authorizer/oauth2/rack_application.rb', line 17

def call(env)
  path = env['PATH_INFO']
  request_method = env['REQUEST_METHOD']

  return handle_authorize(env) if path == AUTHORIZE_PATH && request_method == 'GET'
  return handle_callback(env) if path == CALLBACK_PATH && request_method == 'GET'

  plain_response(400, 'invalid access')
end


27
28
29
30
31
32
33
34
# File 'lib/google_spreadsheet_fetcher/authorizer/oauth2/rack_application.rb', line 27

def cookie_settings(secret: nil)
  {
    domain: 'localhost',
    path: '/',
    expire_after: 3600*24,
    secret: secret || SecureRandom.hex(64)
  }
end