Module: Authlete::Utility
- Included in:
- Client, Request::AuthenticationCallbackRequest, Response::AuthenticationCallbackResponse, Response::BaseResponse, Response::IntrospectionResponse
- Defined in:
- lib/authlete/utility.rb
Instance Method Summary collapse
-
#extract_access_token(request) ⇒ Object
Extract an access token (RFC 6750).
- #extract_boolean_value(hash, key) ⇒ Object
- #extract_integer_value(hash, key) ⇒ Object
- #extract_value(hash, key) ⇒ Object
- #to_rack_response_json(status_code, content) ⇒ Object
- #to_rack_response_www_authenticate(status_code, content) ⇒ Object
Instance Method Details
#extract_access_token(request) ⇒ Object
Extract an access token (RFC 6750)
39 40 41 42 43 44 45 46 47 |
# File 'lib/authlete/utility.rb', line 39 def extract_access_token(request) header = request.env['HTTP_AUTHORIZATION'] if /^Bearer[ ]+(.+)/i =~ header return $1 end return request['access_token'] end |
#extract_boolean_value(hash, key) ⇒ Object
28 29 30 31 32 |
# File 'lib/authlete/utility.rb', line 28 def extract_boolean_value(hash, key) value = extract_value(hash, key) return (value == true || value == 'true') end |
#extract_integer_value(hash, key) ⇒ Object
34 35 36 |
# File 'lib/authlete/utility.rb', line 34 def extract_integer_value(hash, key) extract_value(hash, key).to_i end |
#extract_value(hash, key) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/authlete/utility.rb', line 20 def extract_value(hash, key) if hash.has_key?(key) hash[key] else hash[key.to_s] end end |
#to_rack_response_json(status_code, content) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/authlete/utility.rb', line 49 def to_rack_response_json(status_code, content) [ status_code, { 'Content-Type' => 'application/json;charset=UTF-8', 'Cache-Control' => 'no-store', 'Pragma' => 'no-cache' }, [ content ] ] end |
#to_rack_response_www_authenticate(status_code, content) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/authlete/utility.rb', line 63 def to_rack_response_www_authenticate(status_code, content) [ status_code, { 'WWW-Authenticate' => content, 'Cache-Control' => 'no-store', 'Pragma' => 'no-cache' }, nil ] end |