Skip to content

Commit 66d2e78

Browse files
Releasing federated token details in logs (#186)
Displaying token details as logs
1 parent 838596b commit 66d2e78

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
2-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
33
if (k2 === undefined) k2 = k;
4-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
5-
}) : (function (o, m, k, k2) {
4+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5+
}) : (function(o, m, k, k2) {
66
if (k2 === undefined) k2 = k;
77
o[k2] = m[k];
88
}));
9-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
9+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1010
Object.defineProperty(o, "default", { enumerable: true, value: v });
11-
}) : function (o, v) {
11+
}) : function(o, v) {
1212
o["default"] = v;
1313
});
1414
var __importStar = (this && this.__importStar) || function (mod) {
@@ -140,6 +140,8 @@ function main() {
140140
if (!!federatedToken) {
141141
if (environment != "azurecloud")
142142
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
143+
let [issuer, subjectClaim] = yield jwtParser(federatedToken);
144+
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
143145
}
144146
else {
145147
throw new Error("Could not get ID token for authentication.");
@@ -230,4 +232,12 @@ function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
230232
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
231233
});
232234
}
235+
function jwtParser(federatedToken) {
236+
return __awaiter(this, void 0, void 0, function* () {
237+
let tokenPayload = federatedToken.split('.')[1];
238+
let bufferObj = Buffer.from(tokenPayload, "base64");
239+
let decodedPayload = JSON.parse(bufferObj.toString("utf8"));
240+
return [decodedPayload['iss'], decodedPayload['sub']];
241+
});
242+
}
233243
main();

src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ async function main() {
118118
if (!!federatedToken) {
119119
if (environment != "azurecloud")
120120
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
121+
let [issuer, subjectClaim] = await jwtParser(federatedToken);
122+
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
121123
}
122124
else {
123125
throw new Error("Could not get ID token for authentication.");
@@ -227,4 +229,10 @@ async function executeAzCliCommand(
227229
execOptions.silent = !!silent;
228230
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
229231
}
232+
async function jwtParser(federatedToken: string) {
233+
let tokenPayload = federatedToken.split('.')[1];
234+
let bufferObj = Buffer.from(tokenPayload, "base64");
235+
let decodedPayload = JSON.parse(bufferObj.toString("utf8"));
236+
return [decodedPayload['iss'], decodedPayload['sub']];
237+
}
230238
main();

0 commit comments

Comments
 (0)