Skip to content

Commit

Permalink
Use an OAuth 2.0 access token for Domain-Wide Delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Feb 2, 2024
1 parent 5a50e58 commit d84ef94
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client/workload_identity_federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class WorkloadIdentityFederationClient extends Client implements AuthClie
const pth = `${this._endpoints.iamcredentials}/projects/-/serviceAccounts/${this.#serviceAccount}:signJwt`;

const headers = {
Authorization: `Bearer ${this.getToken()}`,
Authorization: `Bearer ${await this.getToken()}`,
};

const body = {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ async function main(logger: Logger) {
);
}

let accessToken: string;

// If a subject was provided, use the traditional OAuth 2.0 flow to
// perform Domain-Wide Delegation. Otherwise, use the modern IAM
// Credentials endpoints.
let accessToken;
if (accessTokenSubject) {
if (accessTokenLifetime > 3600) {
logger.info(
Expand All @@ -302,7 +303,6 @@ async function main(logger: Logger) {
accessTokenLifetime,
);
const signedJWT = await client.signJWT(unsignedJWT);

accessToken = await iamCredentialsClient.generateDomainWideDelegationAccessToken(signedJWT);
} else {
accessToken = await iamCredentialsClient.generateAccessToken({
Expand Down

0 comments on commit d84ef94

Please sign in to comment.