1
0
Fork 0

Addressed minor comments

pull/887/head
Sourav Chanduka 2021-08-23 10:49:53 +05:30
parent 4631854e0f
commit d9212ff45b
5 changed files with 14 additions and 11 deletions

View File

@ -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)

View File

@ -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"

View File

@ -1,6 +1,6 @@
{
"name": "@actions/core",
"version": "1.5.1",
"version": "1.6.0",
"description": "Actions core lib",
"keywords": [
"github",

View File

@ -351,6 +351,6 @@ export function getState(name: string): string {
return process.env[`STATE_${name}`] || ''
}
export async function getIDToken(aud?: string | undefined): Promise<string> {
export async function getIDToken(aud?: string): Promise<string> {
return await OidcClient.getIDToken(aud)
}

View File

@ -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<string> {
private static async postCall(id_token_url: string, data: TokenRequest): Promise<string> {
const httpclient = OidcClient.createHttpClient()
const res = await httpclient.postJson<TokenResponse>(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<string> {
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) {