Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always sign with scopes on Non-Default Universes #1752

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/auth/jwtclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
scopes = this.defaultScopes;
}

const useScopes =
this.useJWTAccessWithScope ||
this.universeDomain !== DEFAULT_UNIVERSE;

const headers = await this.access.getRequestHeaders(
url ?? undefined,
this.additionalClaims,
// Scopes take precedent over audience for signing,
// so we only provide them if useJWTAccessWithScope is on
this.useJWTAccessWithScope ? scopes : undefined
// so we only provide them if `useJWTAccessWithScope` is on or
// if we are in a non-default universe
useScopes ? scopes : undefined
);

return {headers: this.addSharedMetadataHeaders(headers)};
Expand Down
16 changes: 8 additions & 8 deletions test/test.jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
const keypair = require('keypair');
const PEM_PATH = './test/fixtures/private.pem';
const PEM_CONTENTS = fs.readFileSync(PEM_PATH, 'utf8');
const P12_PATH = './test/fixtures/key.p12';

Check warning on line 31 in test/test.jwt.ts

View workflow job for this annotation

GitHub Actions / lint

'P12_PATH' is assigned a value but never used

nock.disableNetConnect();

Expand Down Expand Up @@ -896,7 +896,7 @@
);
});

it('signs JWT with audience if: user scope = true, default scope = false, audience = falsy, useJWTAccessWithScope = true', async () => {
it('signs JWT with scopes if: user scope = true, default scope = false, audience = falsy, useJWTAccessWithScope = true', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -918,7 +918,7 @@
);
});

it('signs JWT with audience if: user scope = false, default scope = true, audience = falsy, useJWTAccessWithScope = true', async () => {
it('signs JWT with scopes if: user scope = false, default scope = true, audience = falsy, useJWTAccessWithScope = true', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -939,7 +939,7 @@
]);
});

it('signs JWT with audience if: user scope = true, default scope = true, audience = falsy, useJWTAccessWithScope = true', async () => {
it('signs JWT with scopes if: user scope = true, default scope = true, audience = falsy, useJWTAccessWithScope = true', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -962,7 +962,7 @@
);
});

it('signs JWT with audience if: user scope = true, default scope = false, audience = truthy, useJWTAccessWithScope = true', async () => {
it('signs JWT with scopes if: user scope = true, default scope = false, audience = truthy, useJWTAccessWithScope = true', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -984,7 +984,7 @@
);
});

it('signs JWT with audience if: user scope = true, default scope = true, audience = truthy, useJWTAccessWithScope = true', async () => {
it('signs JWT with scopes if: user scope = true, default scope = true, audience = truthy, useJWTAccessWithScope = true', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -1007,7 +1007,7 @@
);
});

it('signs JWT with audience if: user scope = true, default scope = true, audience = truthy, universeDomain = not default universe', async () => {
it('signs JWT with scopes if: user scope = true, default scope = true, audience = truthy, universeDomain = not default universe', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand All @@ -1025,11 +1025,11 @@
stubGetRequestHeaders,
'https//beepboop.googleapis.com',
undefined,
undefined
['scope1', 'scope2']
);
});

it('signs JWT with audience if: user scope = true, default scope = true, audience = truthy, useJWTAccessWithScope = true, universeDomain = not default universe', async () => {
it('signs JWT with scopes if: user scope = true, default scope = true, audience = truthy, useJWTAccessWithScope = true, universeDomain = not default universe', async () => {
const stubGetRequestHeaders = sandbox.stub().returns({});
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({
getRequestHeaders: stubGetRequestHeaders,
Expand Down
Loading