Parent

Class/Module Index [+]

Quicksearch

Google::APIClient::JWTAsserter

Generates access tokens using the JWT assertion profile. Requires a service account & access to the private key.

@example Using Signet

key = Google::APIClient::KeyUtils.load_from_pkcs12('client.p12', 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
  :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
  :audience => 'https://accounts.google.com/o/oauth2/token',
  :scope => 'https://www.googleapis.com/auth/prediction',
  :issuer => '123456-abcdef@developer.gserviceaccount.com',
  :signing_key => key)
client.authorization.fetch_access_token!
client.execute(...)

@deprecated

Service accounts are now supported directly in Signet

@see developers.google.com/accounts/docs/OAuth2ServiceAccount

Attributes

algorithm[RW]

@return [String] Algorithm used for signing

expiry[RW]

@return [Fixnum] How long, in seconds, the assertion is valid for

issuer[RW]

@return [String] ID/email of the issuing party

key[W]

@return [String,OpenSSL::PKey] key for signing assertions

scope[R]

@return [String] Scopes to authorize

skew[RW]

@return [Fixnum] Seconds to expand the issued at/expiry window to account for clock skew

Public Class Methods

new(issuer, scope, key, algorithm = "RS256") click to toggle source

Initializes the asserter for a service account.

@param [String] issuer

Name/ID of the client issuing the assertion

@param [String, Array] scope

Scopes to authorize. May be a space delimited string or array of strings

@param [String,OpenSSL::PKey] key

Key for signing assertions

@param [String] algorithm

Algorithm to use, either 'RS256' for RSA with SHA-256 
or 'HS256' for HMAC with SHA-256
# File lib/google/api_client/auth/jwt_asserter.rb, line 66
def initialize(issuer, scope, key, algorithm = "RS256")
  self.issuer = issuer
  self.scope = scope
  self.expiry = 60 # 1 min default 
  self.skew = 60      
  self.key = key
  self.algorithm = algorithm
end

Public Instance Methods

authorize(person = nil, options={}) click to toggle source

Request a new access token.

@param [String] person

Email address of a user, if requesting a token to act on their behalf

@param [Hash] options

Pass through to Signet::OAuth2::Client.fetch_access_token

@return [Signet::OAuth2::Client] Access token

@see Signet::OAuth2::Client.fetch_access_token!

# File lib/google/api_client/auth/jwt_asserter.rb, line 103
def authorize(person = nil, options={})
  authorization = self.to_authorization(person)
  authorization.fetch_access_token!(options)
  return authorization
end
scope=(new_scope) click to toggle source

Set the scopes to authorize

@param [String, Array] new_scope

Scopes to authorize. May be a space delimited string or array of strings
# File lib/google/api_client/auth/jwt_asserter.rb, line 80
def scope=(new_scope)
  case new_scope
  when Array
    @scope = new_scope.join(' ')
  when String
    @scope = new_scope
  when nil
    @scope = ''
  else
    raise TypeError, "Expected Array or String, got #{new_scope.class}"
  end
end
to_authorization(person = nil) click to toggle source

Builds a Signet OAuth2 client

@return [Signet::OAuth2::Client] Access token

# File lib/google/api_client/auth/jwt_asserter.rb, line 113
def to_authorization(person = nil)
  return Signet::OAuth2::Client.new(
    :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
    :audience => 'https://accounts.google.com/o/oauth2/token',
    :scope => self.scope,
    :issuer => @issuer,
    :signing_key => @key,
    :signing_algorithm => @algorithm,
    :person => person
  )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.