Skip to content

Commit 023be4c

Browse files
committed
Added ability to specify authentication block for controller actions
1 parent 263867c commit 023be4c

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
module GrapeSwaggerRails
22
class ApplicationController < ActionController::Base
3-
#layout :application
3+
before_filter do
4+
if GrapeSwaggerRails.options.authentication_proc
5+
instance_exec(request, &GrapeSwaggerRails.options.authentication_proc)
6+
end
7+
end
8+
49
def index
5-
610
end
711
end
812
end

lib/grape-swagger-rails.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
require "grape-swagger-rails/engine"
22

33
module GrapeSwaggerRails
4-
class Options < Struct.new(:url, :api_key_name, :api_key_type, :api_auth, :headers, :app_name, :app_url)
4+
class Options < Struct.new(:url, :api_key_name, :api_key_type, :api_auth, :headers, :app_name, :app_url, :authentication_proc)
5+
def authenticate_with(&block)
6+
self.authentication_proc = block
7+
end
58
end
69

710
mattr_accessor :options
811

912
self.options = Options.new(
10-
url: '/swagger_doc.json',
11-
api_key_name: 'api_key',
12-
api_key_type: 'query',
13-
api_auth: '', # 'basic'
14-
headers: {},
15-
app_name: 'Swagger',
16-
app_url: 'http://swagger.wordnik.com'
13+
url: '/swagger_doc.json',
14+
api_key_name: 'api_key',
15+
api_key_type: 'query',
16+
api_auth: '', # 'basic'
17+
headers: {},
18+
app_name: 'Swagger',
19+
app_url: 'http://swagger.wordnik.com',
20+
authentication_proc: nil # Proc used as a controller before filter that returns a boolean
1721
)
1822

1923
end

0 commit comments

Comments
 (0)