class Object

Public Instance Methods

generate_access_token() click to toggle source
# File lib/publisher/pf_lab_interface.rb, line 33
def generate_access_token
  uri = URI.parse(self.private_key_hash["token_uri"])
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Post.new(uri.path)
  req['Cache-Control'] = "no-store"
  req.set_form_data({
    grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
    assertion: get_jwt
  })

  resp = JSON.parse(https.request(req).body)
  resp["access_token"]
end
generate_auth(opts={}) click to toggle source
# File lib/publisher/pf_lab_interface.rb, line 48
def generate_auth opts={}
        generate_access_token
end
get_jwt() click to toggle source
# File lib/publisher/pf_lab_interface.rb, line 15
def get_jwt
        puts Base64.encode64(JSON.generate(self.private_key_hash))
        # Get your service account's email address and private key from the JSON key file
        $service_account_email = self.private_key_hash["client_email"]
        $private_key = OpenSSL::PKey::RSA.new self.private_key_hash["private_key"]
          now_seconds = Time.now.to_i
          payload = {:iss => $service_account_email,
                     :sub => $service_account_email,
                     :aud => self.private_key_hash["token_uri"],
                     :iat => now_seconds,
                     :exp => now_seconds + 1, # Maximum expiration time is one hour
                     :scope => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/firebase.database'

                 }
          JWT.encode payload, $private_key, "RS256"
        
end
query() click to toggle source
# File lib/publisher/pf_lab_interface.rb, line 11
def query
{:access_token => auth}
end