Skip to content

Commit

Permalink
feat: add useJWTAccessAlways and defaultServicePath variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Jul 2, 2021
1 parent f8dcb0f commit 57e4dad
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ package-lock.json
yarn.lock
dist/
__pycache__
.DS_Store
2 changes: 2 additions & 0 deletions src/auth/baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export abstract class BaseExternalAccountClient extends AuthClient {
public projectNumber: string | null;
public readonly eagerRefreshThresholdMillis: number;
public readonly forceRefreshOnFailure: boolean;
public useJWTAccessAlways?: boolean;
public defaultServicePath?: string;

/**
* Instantiate a BaseExternalAccountClient instance using the provided JSON
Expand Down
10 changes: 10 additions & 0 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export class GoogleAuth {
* @private
*/
private checkIsGCE?: boolean = undefined;
useJWTAccessAlways?: boolean;
defaultServicePath?: string;

// Note: this properly is only public to satisify unit tests.
// https://github.com/Microsoft/TypeScript/issues/5228
Expand Down Expand Up @@ -456,6 +458,8 @@ export class GoogleAuth {
} else {
(options as JWTOptions).scopes = this.scopes;
client = new JWT(options);
client.defaultServicePath = this.defaultServicePath;
client.useJWTAccessAlways = this.useJWTAccessAlways;
client.defaultScopes = this.defaultScopes;
client.fromJSON(json);
}
Expand Down Expand Up @@ -489,6 +493,8 @@ export class GoogleAuth {
(options as JWTOptions).scopes = this.scopes;
client = new JWT(options);
client.defaultScopes = this.defaultScopes;
client.defaultServicePath = this.defaultServicePath;
client.useJWTAccessAlways = this.useJWTAccessAlways;
client.fromJSON(json);
}
// cache both raw data used to instantiate client and client itself.
Expand Down Expand Up @@ -564,6 +570,8 @@ export class GoogleAuth {
keyFile: this.keyFilename,
});
this.cachedCredential = client;
client.defaultServicePath = this.defaultServicePath;
client.useJWTAccessAlways = this.useJWTAccessAlways;
return resolve(client);
}
} catch (err) {
Expand All @@ -583,6 +591,8 @@ export class GoogleAuth {
options = options || {};
const client = new JWT(options);
client.fromAPIKey(apiKey);
client.defaultServicePath = this.defaultServicePath;
client.useJWTAccessAlways = this.useJWTAccessAlways;
return client;
}

Expand Down
3 changes: 2 additions & 1 deletion src/auth/jwtclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
subject?: string;
gtoken?: GoogleToken;
additionalClaims?: {};

useJWTAccessAlways?: boolean;
defaultServicePath?: string;
private access?: JWTAccess;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/auth/refreshclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class UserRefreshClient extends OAuth2Client {
// In a future gts release, the _propertyName rule will be lifted.
// This is also a hard one because `this.refreshToken` is a function.
_refreshToken?: string | null;
public useJWTAccessAlways?: boolean;
public defaultServicePath?: string;

/**
* User Refresh Token credentials.
Expand Down
19 changes: 19 additions & 0 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,25 @@ describe('googleauth', () => {
const result = auth.fromJSON(json);
assert.strictEqual(undefined, (result as JWT).scopes);
});
it('fromJSON should set useJWTAccessAlways with private key', () => {
auth.useJWTAccessAlways = true;
const json = createJwtJSON();
const result = auth.fromJSON(json);
assert.ok(result.useJWTAccessAlways);
});

it('fromJSON should set default service path with private key', () => {
auth.defaultServicePath = 'a/b/c';
const json = createJwtJSON();
const result = auth.fromJSON(json);
assert.strictEqual(result.defaultServicePath, 'a/b/c');
});

it('fromAPIKey should set useJWTAccessAlways', () => {
auth.useJWTAccessAlways = true;
const client = auth.fromAPIKey(API_KEY);
assert.ok(client.useJWTAccessAlways);
});

it('fromJSON should create JWT with null subject', () => {
const json = createJwtJSON();
Expand Down

0 comments on commit 57e4dad

Please sign in to comment.