Class: Google::IdentityToolkit::Api

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/google/identity_toolkit/api.rb

Overview

Server API for creating login requests & verifying assertions

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Api

Initializes the API

Parameters:

  • api_key (String)

    API key from developer console



20
21
22
# File 'lib/google/identity_toolkit/api.rb', line 20

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#verify_assertion(request_uri, body = nil) ⇒ Hash

Sends an IDP response for verification, returning an assertion if the response is valid

Parameters:

  • request_uri (String)

    URL of the current request

  • body (StringIO) (defaults to: nil)

    Request body (if post)

Returns:

  • (Hash)

    Assertion of user identity

Raises:



38
39
40
41
42
43
44
45
46
47
# File 'lib/google/identity_toolkit/api.rb', line 38

def verify_assertion(request_uri, body=nil)
  request = {
    "requestUri" => request_uri
  }
  request["postBody"] = body.gets unless body.nil?
  response = Api.post('https://www.googleapis.com/identitytoolkit/v1/relyingparty/verifyAssertion', 
    :query => { "key" => @api_key }, :body => request.to_json )
  raise ApiError.new("Error #{response.code} when verifying the assertion") unless response.code == 200
  response.parsed_response
end