diff --git a/README.md b/README.md index 1501e2f9f..5908711db 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ For server-to-server interactions, like those between a web application and Goog client = Google::APIClient.new key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret') - service_account = Google::APIClient::JWTAsserter( + service_account = Google::APIClient::JWTAsserter.new( '123456-abcdef@developer.gserviceaccount.com', 'https://www.googleapis.com/auth/prediction', key) diff --git a/lib/google/api_client/auth/jwt_asserter.rb b/lib/google/api_client/auth/jwt_asserter.rb index a974f8af6..4d912724a 100644 --- a/lib/google/api_client/auth/jwt_asserter.rb +++ b/lib/google/api_client/auth/jwt_asserter.rb @@ -26,7 +26,7 @@ module Google # # client = Google::APIClient.new # key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret') - # service_account = Google::APIClient::JWTAsserter( + # service_account = Google::APIClient::JWTAsserter.new( # '123456-abcdef@developer.gserviceaccount.com', # 'https://www.googleapis.com/auth/prediction', # key) @@ -109,7 +109,7 @@ module Google # Pass through to Signet::OAuth2::Client.fetch_access_token # @return [Signet::OAuth2::Client] Access token # - # @see Signet::OAuth2::Client.fetch_access_token + # @see Signet::OAuth2::Client.fetch_access_token! def authorize(person = nil, options={}) assertion = self.to_jwt(person) authorization = Signet::OAuth2::Client.new( @@ -122,13 +122,27 @@ module Google end end + ## + # Proxy for authorization that allows refreshing the access token + # using assertions instead of refresh tokens. class JWTAuthorization < DelegateClass(Signet::OAuth2::Client) + ## + # Initialize the proxy + # + # @param [Signet::OAuth2::Client] authorization + # Original authorization instance + # @param [Google::APIClient::JWTAsserter] + # Asserter for generating new access tokens + # @param [String] person + # Optional target user if impersonating. def initialize(authorization, asserter, person = nil) @asserter = asserter @person = person super(authorization) end - + + ## + # @see Signet::OAuth2::Client#fetch_access_token! def fetch_access_token!(options={}) new_authorization = @asserter.authorize(@person, options) __setobj__(new_authorization)