This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for impersonating a user when using a service account
Allow `ServiceAccountCredentials` constructors to take an optional `user` argument to specify a user to impersonate. BUG=#15 [email protected] Review URL: https://codereview.chromium.org/893423003
- Loading branch information
Showing
8 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: googleapis_auth | ||
version: 0.2.2 | ||
version: 0.2.3 | ||
author: Dart Team <[email protected]> | ||
description: Obtain Access credentials for Google services using OAuth 2.0 | ||
homepage: https://github.com/dart-lang/googleapis_auth | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ main() { | |
var scopes = ['s1', 's2']; | ||
|
||
test('successfull', () { | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, scopes, | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, null, scopes, | ||
mockClient(expectAsync(successfullSignRequest), expectClose: false)); | ||
|
||
flow.run().then(expectAsync((AccessCredentials credentials) { | ||
|
@@ -59,15 +59,27 @@ main() { | |
})); | ||
}); | ||
|
||
test('successfull-with-user', () { | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, '[email protected]', scopes, | ||
mockClient(expectAsync(successfullSignRequest), expectClose: false)); | ||
|
||
flow.run().then(expectAsync((AccessCredentials credentials) { | ||
expect(credentials.accessToken.data, equals('atok')); | ||
expect(credentials.accessToken.type, equals('Bearer')); | ||
expect(credentials.scopes, equals(['s1', 's2'])); | ||
expectExpiryOneHourFromNow(credentials.accessToken); | ||
})); | ||
}); | ||
|
||
test('invalid-server-response', () { | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, scopes, | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, null, scopes, | ||
mockClient(expectAsync(invalidAccessToken), expectClose: false)); | ||
|
||
expect(flow.run(), throwsA(isException)); | ||
}); | ||
|
||
test('transport-failure', () { | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, scopes, | ||
var flow = new JwtFlow(clientEmail, TestPrivateKey, null, scopes, | ||
transportFailure); | ||
|
||
expect(flow.run(), throwsA(isTransportException)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,17 @@ main() { | |
expect(credentials.email, equals('email')); | ||
expect(credentials.clientId, equals(clientId)); | ||
expect(credentials.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentials.impersonatedUser, isNull); | ||
}); | ||
|
||
test('from-valid-individual-params-with-user', () { | ||
var credentials = new ServiceAccountCredentials( | ||
'email', clientId, TestPrivateKeyString, | ||
impersonatedUser: '[email protected]'); | ||
expect(credentials.email, equals('email')); | ||
expect(credentials.clientId, equals(clientId)); | ||
expect(credentials.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentials.impersonatedUser, equals('[email protected]')); | ||
}); | ||
|
||
test('from-json-string', () { | ||
|
@@ -95,6 +106,18 @@ main() { | |
expect(credentialsFromJson.clientId.identifier, equals('myid')); | ||
expect(credentialsFromJson.clientId.secret, isNull); | ||
expect(credentialsFromJson.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentialsFromJson.impersonatedUser, isNull); | ||
}); | ||
|
||
test('from-json-string-with-user', () { | ||
var credentialsFromJson = | ||
new ServiceAccountCredentials.fromJson( | ||
JSON.encode(credentials), impersonatedUser: '[email protected]'); | ||
expect(credentialsFromJson.email, equals('[email protected]')); | ||
expect(credentialsFromJson.clientId.identifier, equals('myid')); | ||
expect(credentialsFromJson.clientId.secret, isNull); | ||
expect(credentialsFromJson.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentialsFromJson.impersonatedUser, equals('[email protected]')); | ||
}); | ||
|
||
test('from-json-map', () { | ||
|
@@ -104,6 +127,18 @@ main() { | |
expect(credentialsFromJson.clientId.identifier, equals('myid')); | ||
expect(credentialsFromJson.clientId.secret, isNull); | ||
expect(credentialsFromJson.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentialsFromJson.impersonatedUser, isNull); | ||
}); | ||
|
||
test('from-json-map-with-user', () { | ||
var credentialsFromJson = | ||
new ServiceAccountCredentials.fromJson( | ||
credentials, impersonatedUser: '[email protected]'); | ||
expect(credentialsFromJson.email, equals('[email protected]')); | ||
expect(credentialsFromJson.clientId.identifier, equals('myid')); | ||
expect(credentialsFromJson.clientId.secret, isNull); | ||
expect(credentialsFromJson.privateKey, equals(TestPrivateKeyString)); | ||
expect(credentialsFromJson.impersonatedUser, equals('[email protected]')); | ||
}); | ||
}); | ||
|
||
|