From d9212ff45bdc6cdba5d89ef57dc159ff125a4cf5 Mon Sep 17 00:00:00 2001 From: Sourav Chanduka Date: Mon, 23 Aug 2021 10:49:53 +0530 Subject: [PATCH] Addressed minor comments --- packages/core/RELEASES.md | 3 +++ packages/core/package-lock.json | 4 ++-- packages/core/package.json | 2 +- packages/core/src/core.ts | 2 +- packages/core/src/oidc-utils.ts | 14 +++++++------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/core/RELEASES.md b/packages/core/RELEASES.md index c53d4569..88d931fc 100644 --- a/packages/core/RELEASES.md +++ b/packages/core/RELEASES.md @@ -1,5 +1,8 @@ # @actions/core Releases +### 1.6.0 +- [Added OIDC Client function `getIDToken`](https://github.com/actions/toolkit/pull/887) + ### 1.4.0 - [Added the `getMultilineInput` function](https://github.com/actions/toolkit/pull/829) diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index b7390ce2..7eb2b6a7 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@actions/core", - "version": "1.5.1", + "version": "1.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@actions/core", - "version": "1.5.1", + "version": "1.6.0", "license": "MIT", "dependencies": { "@actions/http-client": "^1.0.11" diff --git a/packages/core/package.json b/packages/core/package.json index ac596714..8d7a3997 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@actions/core", - "version": "1.5.1", + "version": "1.6.0", "description": "Actions core lib", "keywords": [ "github", diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 7f509968..d31550a4 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -351,6 +351,6 @@ export function getState(name: string): string { return process.env[`STATE_${name}`] || '' } -export async function getIDToken(aud?: string | undefined): Promise { +export async function getIDToken(aud?: string): Promise { return await OidcClient.getIDToken(aud) } \ No newline at end of file diff --git a/packages/core/src/oidc-utils.ts b/packages/core/src/oidc-utils.ts index 46b0416f..ff69a8e8 100644 --- a/packages/core/src/oidc-utils.ts +++ b/packages/core/src/oidc-utils.ts @@ -5,11 +5,11 @@ import {BearerCredentialHandler} from '@actions/http-client/auth' import {debug, setSecret} from './core' interface TokenRequest { - aud: string | undefined + aud?: string } interface TokenResponse { - value: string | undefined + value?: string } export class OidcClient { @@ -45,7 +45,9 @@ export class OidcClient { return runtimeUrl + '?api-version=' + OidcClient.getApiVersion() } - private static async postCall(httpclient: actions_http_client.HttpClient, id_token_url: string, data: TokenRequest): Promise { + private static async postCall(id_token_url: string, data: TokenRequest): Promise { + const httpclient = OidcClient.createHttpClient() + const res = await httpclient.postJson(id_token_url,data).catch((error) => { throw new Error( `Failed to get ID Token. \n @@ -55,7 +57,7 @@ export class OidcClient { }) const id_token = res.result?.value - if (id_token === undefined) { + if (!id_token) { throw new Error('Response json body do not have ID Token field') } return id_token @@ -64,8 +66,6 @@ export class OidcClient { static async getIDToken(audience: string | undefined): Promise { try { - const httpclient = OidcClient.createHttpClient() - // New ID Token is requested from action service const id_token_url: string = OidcClient.getIDTokenUrl() @@ -75,7 +75,7 @@ export class OidcClient { debug(`audience is ${!!audience ? audience : 'not defined'}`) - const id_token = await OidcClient.postCall(httpclient ,id_token_url, data) + const id_token = await OidcClient.postCall(id_token_url, data) setSecret(id_token) return id_token } catch (error) {