Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

safer checks around auth_token parsing

  • Loading branch information...
commit 4dabd15cb3e9cabfe5e9a6cf82efc11ae2541324 1 parent 6e158cb
@theganyo authored
Showing with 18 additions and 11 deletions.
  1. +18 −11 lib/usergrid/core/resource.rb
View
29 lib/usergrid/core/resource.rb
@@ -6,7 +6,7 @@ class Resource < RestClient::Resource
DEFAULT_API_URL = 'https://api.usergrid.com'
TYPE_HEADERS = { :content_type => :json, :accept => :json }
- attr_reader :current_user, :auth_token, :api_url
+ attr_reader :current_user, :api_url
def initialize(resource_url=DEFAULT_API_URL, api_url=nil, options={}, response=nil)
options[:headers] = TYPE_HEADERS.merge options[:headers] || {}
@@ -34,7 +34,7 @@ def logout
end
def logged_in?
- !!@auth_token
+ !!auth_token
end
def management
@@ -87,16 +87,7 @@ def put(payload, additional_headers={}, &block)
self.response = super payload, additional_headers, &block
end
- protected
-
- attr_reader :response
-
- def response=(response)
- @response = response
- end
-
def auth_token=(auth_token)
- @auth_token = auth_token
if auth_token
@options[:headers].merge!({ Authorization: "Bearer #{auth_token}" })
else
@@ -104,6 +95,22 @@ def auth_token=(auth_token)
end
end
+ def auth_token
+ begin
+ @options[:headers][:Authorization].gsub 'Bearer ', ''
+ rescue
+ nil
+ end
+ end
+
+ protected
+
+ attr_reader :response
+
+ def response=(response)
+ @response = response
+ end
+
# add verbose debugging of response body
def handle_response(response, request, result, &block)
LOG.debug "response.body = #{response}"
Please sign in to comment.
Something went wrong with that request. Please try again.