Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Jan 1, 2024
1 parent 019192f commit b9de761
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function main() {
try {
core.startGroup('Setup JFrog CLI');
utils_1.Utils.setCliEnv();
console.log("ERAN CHECK: ####################### 11 #######################"); // TODO del
console.log("ERAN CHECK: ####################### 12 #######################"); // TODO del
let accessToken = yield utils_1.Utils.getJfrogAccessToken();
console.log(`ERAN CHECK: finished access token flow with access token: ${accessToken}`); // TODO del
yield utils_1.Utils.getAndAddCliToPath();
Expand Down
21 changes: 15 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,33 @@ class Utils {
static getAccessTokenFromJWT(basicUrl, jsonWebToken) {
return __awaiter(this, void 0, void 0, function* () {
const exchangeUrl = basicUrl.replace(/\/$/, '') + "/access/api/v1/oidc/token";
console.log(`ERAN CHECK: Url for REST command: ${exchangeUrl}`); // TODO del
console.log(`ERAN CHECK: Exchanging JWT with ACCESS TOKEN. Url for REST command: ${exchangeUrl}`); // TODO del
console.log("Exchanging JSON web token with access token");
const audience = core.getInput(Utils.OIDC_AUDIENCE_ARG, { required: false });
const httpClient = new http_client_1.HttpClient();
// TODO fix request
try {
const dataString = JSON.stringify({
/*
const dataString: string = JSON.stringify({
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
subject_token_type: "urn:ietf:params:oauth:token-type:access_token",
subject_token_type: "urn:ietf:params:oauth:token-type:access_token", //TODO try: id-token -> access_token
subject_token: jsonWebToken,
provider_name: "github-oidc" // https://token.actions.githubusercontent.com
//assertion: jsonWebToken,
//audience: audience,
//audience: audience, //TODO should I pass audience here as well? it was passed to the JWT generator
});
const headers = {
*/
const data = `{
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"subject_token_type": "urn:ietf:params:oauth:token-type:id_token",
"subject_token": "${jsonWebToken}",
"provider_name": "github-oidc-integration"
}`;
const additionalHeaders = {
'Content-Type': 'application/json',
};
console.log(`ERAN CHECK: starting POST`); // TODO del
const response = yield httpClient.post(exchangeUrl, dataString, headers);
const response = yield httpClient.post(exchangeUrl, data, additionalHeaders);
console.log(`ERAN CHECK: POST succeeded`); // TODO del
const responseData = yield response.readBody();
console.log(`ERAN CHECK: response string: ${responseData}`); // TODO del
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function main() {
try {
core.startGroup('Setup JFrog CLI');
Utils.setCliEnv();
console.log("ERAN CHECK: ####################### 12 #######################") // TODO del
console.log("ERAN CHECK: ####################### 13 #######################") // TODO del
let accessToken :string = await Utils.getJfrogAccessToken()
console.log(`ERAN CHECK: finished access token flow with access token: ${accessToken}`) // TODO del
await Utils.getAndAddCliToPath();
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Utils {

const data = `{
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"subject_token_type": "urn:ietf:params:oauth:token-type:id_token",
"subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
"subject_token": "${jsonWebToken}",
"provider_name": "github-oidc-integration"
}`;
Expand Down

0 comments on commit b9de761

Please sign in to comment.