Skip to content

Commit

Permalink
Merge pull request googleapis#23 from layby42/master
Browse files Browse the repository at this point in the history
Pull request for googleapis#22
  • Loading branch information
sporkmonger committed Jan 12, 2013
2 parents 280cdff + 7d204ac commit 47bdbc1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/google/api_client/auth/jwt_asserter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def scope=(new_scope)
#
# @see Signet::OAuth2::Client.fetch_access_token!
def authorize(person = nil, options={})
authorization = self.to_authorization
authorization = self.to_authorization(person)
authorization.fetch_access_token!(options)
return authorization
end
Expand Down
20 changes: 20 additions & 0 deletions spec/google/api_client/service_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@
claim["scope"].should == 'scope1 scope2'
end

it 'should allow impersonation' do
conn = stub_connection do |stub|
stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body])
JWT.decode(params.assoc("assertion").last, @key.public_key)
params.assoc("grant_type").should == ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
[200, {}, '{
"access_token" : "1/abcdef1234567890",
"token_type" : "Bearer",
"expires_in" : 3600
}']
end
end
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
auth = asserter.authorize('user1@email.com', { :connection => conn })
auth.should_not == nil?
auth.person.should == 'user1@email.com'
conn.verify
end

it 'should send valid access token request' do
conn = stub_connection do |stub|
stub.post('/o/oauth2/token') do |env|
Expand Down

0 comments on commit 47bdbc1

Please sign in to comment.