Skip to content

Commit a4351ca

Browse files
committed
feat: AL-9
1 parent 4548992 commit a4351ca

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/auth/jwtclient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
122122
(!this.hasUserScopes() && url) ||
123123
(this.useJWTAccessWithScope && this.hasAnyScopes()) ||
124124
this.universeDomain !== DEFAULT_UNIVERSE;
125+
126+
if (this.subject && this.universeDomain !== DEFAULT_UNIVERSE) {
127+
throw new RangeError(
128+
`Service Account user is configured for the credential. Domain-wide delegation is not supported in universes other than ${DEFAULT_UNIVERSE}`
129+
);
130+
}
131+
125132
if (!this.apiKey && useSelfSignedJWT) {
126133
if (
127134
this.additionalClaims &&

test/test.jwt.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ describe('jwt', () => {
10161016
10171017
key: fs.readFileSync(PEM_PATH, 'utf8'),
10181018
scopes: ['scope1', 'scope2'],
1019-
subject: '[email protected]',
10201019
universeDomain: 'my-universe.com',
10211020
});
10221021
jwt.defaultScopes = ['scope1', 'scope2'];
@@ -1039,7 +1038,6 @@ describe('jwt', () => {
10391038
10401039
key: fs.readFileSync(PEM_PATH, 'utf8'),
10411040
scopes: ['scope1', 'scope2'],
1042-
subject: '[email protected]',
10431041
universeDomain: 'my-universe.com',
10441042
});
10451043
jwt.useJWTAccessWithScope = true;
@@ -1054,6 +1052,27 @@ describe('jwt', () => {
10541052
);
10551053
});
10561054

1055+
it('throws on domain-wide delegation on non-default universe', async () => {
1056+
const stubGetRequestHeaders = sandbox.stub().returns({});
1057+
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
1058+
getRequestHeaders: stubGetRequestHeaders,
1059+
});
1060+
const jwt = new JWT({
1061+
1062+
key: fs.readFileSync(PEM_PATH, 'utf8'),
1063+
scopes: ['scope1', 'scope2'],
1064+
subject: '[email protected]',
1065+
universeDomain: 'my-universe.com',
1066+
});
1067+
jwt.useJWTAccessWithScope = true;
1068+
jwt.defaultScopes = ['scope1', 'scope2'];
1069+
1070+
await assert.rejects(
1071+
() => jwt.getRequestHeaders('https//beepboop.googleapis.com'),
1072+
/Domain-wide delegation is not supported in universes other than/
1073+
);
1074+
});
1075+
10571076
it('does not use self signed JWT if target_audience provided', async () => {
10581077
const JWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
10591078
getRequestHeaders: sinon.stub().returns({}),

0 commit comments

Comments
 (0)