authlete 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,9 +39,8 @@ module Authlete
39
39
  # Request
40
40
  request = Rack::Request.new(env)
41
41
 
42
- # If the path is different from the name of the authentication
43
- # callback endpoint.
44
- if request.post? == false || request.path_info != authentication_callback_endpoint_path()
42
+ # If the request is not an authentication callback request.
43
+ if match_authentication_callback_request(request) == false
45
44
  # If this class is used as a Rack middleware.
46
45
  if @app && @app.respond_to?(:call)
47
46
  # Call chain to the next Rack middleware.
@@ -93,6 +92,12 @@ module Authlete
93
92
 
94
93
  private
95
94
 
95
+ def match_authentication_callback_request(request)
96
+ request.post? &&
97
+ request.path_info == authentication_callback_endpoint_path() &&
98
+ %r{^application/json}i === request.content_type
99
+ end
100
+
96
101
  def do_authenticate_api_call(env)
97
102
  # API key and secret for the API call to the authentication endpoint.
98
103
  api_key, api_secret = nil, nil
@@ -116,7 +121,7 @@ module Authlete
116
121
  'Content-Type' => 'text/plain'
117
122
  },
118
123
  [
119
- "'#{request.request_method} #{request.path_info}' is not found on this server."
124
+ "Not Found: #{request.request_method} #{request.path_info} (#{request.content_type})"
120
125
  ]
121
126
  ]
122
127
  end
@@ -137,14 +142,13 @@ module Authlete
137
142
 
138
143
  # 400 Bad Request
139
144
  def generate_authentication_callback_request_format_error(exception)
140
- p exception
141
145
  [
142
146
  400,
143
147
  {
144
148
  'Content-Type' => 'text/plain',
145
149
  },
146
150
  [
147
- 'The format of the authentication callback request was wrong.'
151
+ "The format of the authentication callback request was wrong: #{exception.to_s}"
148
152
  ]
149
153
  ]
150
154
  end
@@ -153,8 +157,11 @@ module Authlete
153
157
  # In case someone has already read it.
154
158
  request.body.rewind
155
159
 
160
+ # JSON
161
+ json = request.body.read
162
+
156
163
  # Parse the authentication callback request.
157
- Authlete::Request::AuthenticationCallbackRequest.parse(request.body.read)
164
+ Authlete::Request::AuthenticationCallbackRequest.parse(json)
158
165
  end
159
166
 
160
167
  protected
@@ -1,3 +1,3 @@
1
1
  module Authlete
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-21 00:00:00.000000000 Z
12
+ date: 2014-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client