Module: SimpleOAuth::OAuth2::ResponseBody

Defined in:
lib/simple_oauth/oauth2/response_body.rb,
sig/simple_oauth/oauth2.rbs

Overview

Parses the JSON bodies returned by OAuth 2.0 endpoints

Class Method Summary collapse

Class Method Details

.parse(body) ⇒ Hash{String => Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a response body into a Hash, or an empty Hash if it is not a JSON object

Examples:

SimpleOAuth::OAuth2::ResponseBody.parse('{"error":"invalid_grant"}')
# => {"error" => "invalid_grant"}

Parameters:

  • body (String, nil)

    the response body

Returns:

  • (Hash{String => Object})

    the parsed object



19
20
21
22
23
# File 'lib/simple_oauth/oauth2/response_body.rb', line 19

def self.parse(body)
  Hash.try_convert(JSON.parse(body.to_s)) || {}
rescue JSON::ParserError
  {}
end