Skip to content

Adding API Key doesn't appear to do anything #13

Open
@sunnyrjuneja

Description

@sunnyrjuneja

Hi,

My initializer looks something like this:

GrapeSwaggerRails.options.tap do |o|
  # other details omitted
  o.before_filter do |request|
    authenticate_with_http_basic do |user, pass|
      user == ENV['basic_auth_username'] && password == ENV['basic_auth_password']
    end
  end
  o.api_auth     = 'bearer'
  o.api_key_name = 'Authorization'
  o.api_key_type = 'header'
end

When I fill in my API key and try to explore the API, my API returns that I'm not authenticated. Chrome headers show my response looks like this:

Remote Address:127.0.0.1:3000
Request URL:http://api.rails-app.dev:3000/users/me
Request Method:GET
Status Code:401 Unauthorized
Request Headersview source
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:application/json
Cookie:_Swyp_session=eUJVWkFkVDBsY0JUM2lsUlJmK1l3ekZSZkYzWkJob0RtdnZCeS9WVnRzMzYrSWZWY3IrRHk3OG5CWGRoblE1eWdCaEJSZEtQYU8rSk1yci9CLzJsZEFGQWNLYVBia01mbXNBeGViZkxkbWlhc3pDVXg5K0FFa2lJbzFMVTAvTlZKbVNOcmwzLzBwNHJaVVJUT2U0eVZRPT0tLWMwYkZDRVZjT3I0VjYwdzVXY05CakE9PQ%3D%3D--ce1311b8a602a03f272492ae3cdd2b9576bacced
Host:api.rails-app.dev:3000
Referer:http://api.rails-app.dev:3000/swagger
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/39.0.2171.65 Chrome/39.0.2171.65 Safari/537.36

The swaggerApi object doesn't appear to be including any authorization handlers either.

SwaggerApi {url: "http://api.rails-app.dev:3000/swagger_doc", debug: false, basePath: "http://api.rails-app.dev:3000/swagger_doc", authorizations: null, authorizationScheme: null…}

image

My Gemfile.lock looks like this:

    grape (0.10.1)
      activesupport
      builder
      hashie (>= 2.1.0)
      multi_json (>= 1.3.2)
      multi_xml (>= 0.5.2)
      rack (>= 1.3.0)
      rack-accept
      rack-mount
      virtus (>= 1.0.0)
    grape-entity (0.4.5)
      activesupport
      multi_json (>= 1.3.2)
    grape-swagger (0.10.1)
      grape (>= 0.8.0)
      grape-entity
    grape-swagger-rails (0.1.0)
      grape-swagger (>= 0.7.2)
      railties (>= 3.2.12)

I looked around in the code to try to debug this myself but I couldn't quite figure out where the options were being read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions