Skip to content

Commit

Permalink
rename jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
vchrisb committed Apr 22, 2024
1 parent 2d18174 commit 77e12cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ out
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.vscode
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ steps:
* `api`
* Url of the cloud controller api
* required
* `client_assertion`
* jwt for usage with `private_key_jwt`
* `audience`
* audience for requesting the Github `id_token` used for JWT Bearer Token Grant
* required
* default: `uaa`
* `client_id`
* client id for `client_credentals` or `jwt-bearer`
* `client_secret`
Expand All @@ -51,8 +53,8 @@ steps:
* `client_credentals`
* `private_key_jwt`
* `jwt-bearer`
* `id_token`
* id_token to be used for `jwt-bearer`, if not specified a Github id_token will be requested
* `jwt`
* jwt for usage with `private_key_jwt` or `jwt-bearer`. If none is specified for `jwt-bearer`, a Github `id_token` will be requested
* `username`
* username for `password` grant
* `password`
Expand All @@ -65,10 +67,6 @@ steps:
* cf cli version
* required
* default: `8.7.10`
* `audience`
* audience for requesting the id_token used for JWT Bearer Token Grant
* required
* default: `uaa`

## Advanced

Expand Down
7 changes: 2 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ inputs:
description: "github id_token audience"
required: false
default: "uaa"
client_assertion:
description: "client assertion for requesting token"
required: true
client_id:
description: "client id"
required: false
Expand All @@ -28,8 +25,8 @@ inputs:
description: "grant type for requesting token"
required: true
default: "password"
id_token:
description: "id_token for JWT Bearer Token Grant"
jwt:
description: "jwt for usage with `private_key_jwt` or `jwt-bearer`."
required: false
username:
description: "username"
Expand Down
17 changes: 8 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28879,11 +28879,10 @@ function run() {
try {
let api = core.getInput("api", { required: true });
let grant_type = core.getInput("grant_type", { required: true });
let client_assertion = core.getInput("client_assertion");
let client_id = core.getInput("client_id");
let client_secret = core.getInput("client_secret");
let command = core.getInput("command");
let id_token = core.getInput("id_token");
let jwt = core.getInput("jwt");
let username = core.getInput("username");
let password = core.getInput("password");
let org = core.getInput("org");
Expand All @@ -28898,22 +28897,22 @@ function run() {
if (!audience || !client_id || !client_secret) {
throw new Error(`>>> For JWT Bearer Token Grant audience, client_id and client_secret need to be provided`);
}
if (!id_token) {
id_token = yield request_github_idToken(audience);
core.info(">>> Successfully requested github id_token");
if (!jwt) {
jwt = yield request_github_idToken(audience);
core.info(">>> Successfully requested github id token");
}
let uaaEndpoint = JSON.parse(fs.readFileSync(cf_config)).UaaEndpoint;
let token = yield request_token_jwt_bearer(uaaEndpoint, client_id, client_secret, id_token);
let token = yield request_token_jwt_bearer(uaaEndpoint, client_id, client_secret, jwt);
core.info(">>> Successfully requested uaa token using JWT Bearer Token Grant");
yield update_cf_token(token);
core.info(">>> Successfully updated token in cf config");
}
else if (grant_type == "private_key_jwt") {
if (!client_assertion) {
throw new Error(`>>> For Client Credentials Grant using private_key_jwt, client_assertion needs to be provided`);
if (!jwt) {
throw new Error(`>>> For Client Credentials Grant using private_key_jwt, jwt needs to be provided`);
}
let uaaEndpoint = JSON.parse(fs.readFileSync(cf_config)).UaaEndpoint;
let token = yield request_token_jwt(uaaEndpoint, client_assertion);
let token = yield request_token_jwt(uaaEndpoint, jwt);
core.info(">>> Successfully requested uaa token using Client Credentials Grant with private_key_jwt");
yield update_cf_token(token);
core.info(">>> Successfully updated token in cf config");
Expand Down
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ async function run() {
try {
let api = core.getInput("api", { required: true });
let grant_type = core.getInput("grant_type", { required: true });
let client_assertion = core.getInput("client_assertion");
let client_id = core.getInput("client_id");
let client_secret = core.getInput("client_secret");
let command = core.getInput("command");
let id_token = core.getInput("id_token");
let jwt = core.getInput("jwt");
let username = core.getInput("username");
let password = core.getInput("password");
let org = core.getInput("org");
Expand All @@ -117,30 +116,30 @@ async function run() {
`>>> For JWT Bearer Token Grant audience, client_id and client_secret need to be provided`,
);
}
if (!id_token) {
id_token = await request_github_idToken(audience);
core.info(">>> Successfully requested github id_token");
if (!jwt) {
jwt = await request_github_idToken(audience);
core.info(">>> Successfully requested github id token");
}
let uaaEndpoint = JSON.parse(fs.readFileSync(cf_config)).UaaEndpoint;
let token = await request_token_jwt_bearer(
uaaEndpoint,
client_id,
client_secret,
id_token,
jwt,
);
core.info(
">>> Successfully requested uaa token using JWT Bearer Token Grant",
);
await update_cf_token(token);
core.info(">>> Successfully updated token in cf config");
} else if (grant_type == "private_key_jwt") {
if (!client_assertion) {
if (!jwt) {
throw new Error(
`>>> For Client Credentials Grant using private_key_jwt, client_assertion needs to be provided`,
`>>> For Client Credentials Grant using private_key_jwt, jwt needs to be provided`,
);
}
let uaaEndpoint = JSON.parse(fs.readFileSync(cf_config)).UaaEndpoint;
let token = await request_token_jwt(uaaEndpoint, client_assertion);
let token = await request_token_jwt(uaaEndpoint, jwt);
core.info(
">>> Successfully requested uaa token using Client Credentials Grant with private_key_jwt",
);
Expand Down

0 comments on commit 77e12cb

Please sign in to comment.