mirror of https://github.com/actions/toolkit
Resolved issues
parent
c45ad60078
commit
53a752919b
|
@ -1,10 +1,19 @@
|
|||
var httpclient = require("@actions/http-client")
|
||||
var configvar = require("./../src/internal/config-variables")
|
||||
var httpclient = require('@actions/http-client')
|
||||
var configvar = require('./../src/internal/config-variables')
|
||||
var main = require('./../src/main')
|
||||
|
||||
describe('oidc-client-tests', () => {
|
||||
it('Get Http Client', async () => {
|
||||
//const http = new httpclient('actions/oidc-client')
|
||||
expect(httpclient).toBeDefined()
|
||||
const http = new httpclient.HttpClient('actions/oidc-client')
|
||||
expect(http).toBeDefined()
|
||||
})
|
||||
|
||||
it('HTTP get request to get token endpoint', async () => {
|
||||
const http = new httpclient.HttpClient('actions/oidc-client')
|
||||
const res = await http.get(
|
||||
'https://ghactionsoidc.azurewebsites.net/.well-known/openid-configuration'
|
||||
)
|
||||
expect(res.message.statusCode).toBe(200)
|
||||
})
|
||||
|
||||
it('Get token endpoint', async () => {
|
||||
|
@ -12,6 +21,10 @@ describe('oidc-client-tests', () => {
|
|||
expect(url).toBeDefined()
|
||||
})
|
||||
|
||||
it('Fetch Id token', async () => {
|
||||
var id_token = main.getIDToken('helloworld')
|
||||
expect(id_token).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
/*test('HTTP get request to get token endpoint', async () => {
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run package && npm test",
|
||||
"tsc":"tsc",
|
||||
"type": "module"
|
||||
"tsc":"tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/souravchanduka/toolkit.git"
|
||||
"url": "git+https://github.com/souravchanduka/toolkit.git",
|
||||
"directory": "packages/oidc-client"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
|
@ -32,22 +32,20 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@octokit/core": "^3.4.0"
|
||||
"@octokit/core": "^3.4.0",
|
||||
"jwt-decode":"3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^14.14.9",
|
||||
"@typescript-eslint/parser": "^4.8.1",
|
||||
"@vercel/ncc": "^0.25.1",
|
||||
"eslint": "^7.17.0",
|
||||
"eslint-plugin-github": "^4.1.3",
|
||||
"eslint-plugin-jest": "^24.1.3",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "2.2.1",
|
||||
"ts-jest": "^26.4.4",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^4.1.3",
|
||||
"jwt-decode": "3.1.2"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/souravchanduka/toolkit/issues"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export function getRuntimeToken(): string {
|
||||
const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imlmb2lQTVA1ZlVaUFBkUnV4WXVPbklNUHVEcyJ9.eyJuYW1laWQiOiJkZGRkZGRkZC1kZGRkLWRkZGQtZGRkZC1kZGRkZGRkZGRkZGQiLCJzY3AiOiJBY3Rpb25zLkdlbmVyaWNSZWFkOjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCBBY3Rpb25zLlVwbG9hZEFydGlmYWN0czowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAvMTpCdWlsZC9CdWlsZC8yIERpc3RyaWJ1dGVkVGFzay5HZW5lcmF0ZUlkVG9rZW46YzU3NjQ3Y2QtZGEyMy00YzkwLWEzNWEtY2QzMjhhZTc1ZTBlOmNhMzk1MDg1LTA0MGEtNTI2Yi0yY2U4LWJkYzg1ZjY5Mjc3NCBMb2NhdGlvblNlcnZpY2UuQ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T5KgeuUHAEnIVzgT474BoUEsI1NwFMzxx56f-68jgf088fJfbF9BRv609o0pnrYpHGs8g1lJoy1D0VRfOluxGhpbhrfFnNqbVJPTE4l1KyBvYjAfh5T9qBu1VFv7tR23siq0a1F4nPIVLh9Jd1g1YBIcFd7ejj_vEEyo2UGjXlNlc9pO9xrmjy_1wPggnX5OmndSPozK-oho1YCIuhL8TZomHeaX6qXeXcCakR_Lmw"//process.env['ACTIONS_RUNTIME_TOKEN']
|
||||
const token = process.env['ACTIONS_RUNTIME_TOKEN']
|
||||
if (!token) {
|
||||
throw new Error('Unable to get ACTIONS_RUNTIME_TOKEN env variable')
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ export function getRuntimeToken(): string {
|
|||
}
|
||||
|
||||
export function getIDTokenUrl(): string {
|
||||
const runtimeUrl = "https://neha.ngrok.io/5BIeW5yLeO4xcIjKhPUlNw8vNEKgp3rNJJO0ZaEk4usJseJjZ3/00000000-0000-0000-0000-000000000000/_apis/distributedtask/hubs/Actions/plans/c57647cd-da23-4c90-a35a-cd328ae75e0e/jobs/ca395085-040a-526b-2ce8-bdc85f692774/idtoken"//process.env['ACTIONS_ID_TOKEN_REQUEST_URL']
|
||||
const runtimeUrl = process.env['ACTIONS_ID_TOKEN_REQUEST_URL']
|
||||
if (!runtimeUrl) {
|
||||
throw new Error('Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable')
|
||||
}
|
||||
return runtimeUrl
|
||||
return runtimeUrl.replace("pipelines.codedev.ms","neha.ngrok.io")
|
||||
}
|
||||
|
||||
export function getIDTokenFromEnv(): string {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
isSuccessStatusCode,
|
||||
getApiVersion
|
||||
} from './internal/utils'
|
||||
|
||||
import jwt_decode from 'jwt-decode'
|
||||
import {getIDTokenFromEnv, getIDTokenUrl} from './internal/config-variables'
|
||||
|
||||
export async function getIDToken(audience: string): Promise<string> {
|
||||
|
@ -15,10 +15,16 @@ export async function getIDToken(audience: string): Promise<string> {
|
|||
let id_token: string = getIDTokenFromEnv()
|
||||
if (id_token !== undefined) {
|
||||
const secondsSinceEpoch = Math.round(Date.now() / 1000)
|
||||
const id_token_json = JSON.parse(id_token)
|
||||
if (parseInt(id_token_json['exp']) - secondsSinceEpoch > 120)
|
||||
// Expiry time is more than 2 mins
|
||||
return id_token
|
||||
const id_token_json: any = jwt_decode(id_token)
|
||||
if('exp' in id_token_json) {
|
||||
if (id_token_json['exp'] - secondsSinceEpoch > 300) {
|
||||
// Expiry time is more than 5 mins
|
||||
return id_token
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error('Expiry time not defined in ID Token')
|
||||
}
|
||||
}
|
||||
|
||||
// New ID Token is requested from action service
|
||||
|
@ -75,4 +81,4 @@ export async function getIDToken(audience: string): Promise<string> {
|
|||
|
||||
//module.exports.getIDToken = getIDToken
|
||||
|
||||
getIDToken('helloworld')
|
||||
//getIDToken('ghactions')
|
||||
|
|
Loading…
Reference in New Issue