Skip to content

Commit

Permalink
Change outputs jf-oidc -> oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed May 20, 2024
1 parent 77463d2 commit a480950
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/oidc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ jobs:
- name: Test User Output
shell: bash
run: test -n "${{ steps.setup-jfrog-cli.outputs.jf-oidc-user }}"
run: test -n "${{ steps.setup-jfrog-cli.outputs.oidc-user }}"

- name: Test Token Output
shell: bash
run: test -n "${{ steps.setup-jfrog-cli.outputs.jf-oidc-token }}"
run: test -n "${{ steps.setup-jfrog-cli.outputs.oidc-token }}"

# Removing the OIDC integration will remove the Identity Mapping as well
- name: Delete OIDC integration
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ Example step utilizing OpenID Connect:
with:
oidc-provider-name: setup-jfrog-cli
```
Notice: when using the oidc authentication, the action outputs both the oidc token and the oidc token username which can be used inside the current workflow for logging into the JFrog platform through other actions/clients (for example, for using with docker login).
The outputs added are jf-oidc-token and jf-oidc-user respectively.

**Notice:** When using OIDC authentication, this action outputs both the OIDC token and the OIDC token username. These can be utilized within the current workflow to log into the JFrog platform through other actions or clients (e.g., for use with `docker login`). The added outputs are `oidc-token` and `oidc-user`, respectively.

</details>

Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ inputs:
description: "By default, this is the URL of the GitHub repository owner, such as the organization that owns the repository."
required: false
outputs:
jf-oidc-token:
description: "JFrog oidc token generated by the JFrog CLI when setting oidc-provider-name."
jf-oidc-user:
description: "JFrog OIDC username from the oidc token generated by the Setup JFrog CLI when setting oidc-provider-name."
oidc-token:
description: "JFrog OIDC token generated by the Setup JFrog CLI when setting oidc-provider-name."
oidc-user:
description: "JFrog OIDC username from the OIDC token generated by the Setup JFrog CLI when setting oidc-provider-name."
runs:
using: "node20"
main: "lib/main.js"
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ class Utils {
// Making sure the token is treated as a secret
core.setSecret(oidcToken);
// Output the oidc access token as a secret
core.setOutput('jf-oidc-token', oidcToken);
core.setOutput('oidc-token', oidcToken);
// Output the user from the oidc access token subject as a secret
let payload = this.decodeOidcToken(oidcToken);
let tokenUser = this.extractTokenUser(payload.sub);
// Mark the user as a secret
core.setSecret(tokenUser);
// Output the user from the oidc access token subject extracted from the last section of the subject
core.setOutput('jf-oidc-user', tokenUser);
core.setOutput('oidc-user', tokenUser);
}
/**
* Extract the username from the OIDC access token subject.
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ export class Utils {
// Making sure the token is treated as a secret
core.setSecret(oidcToken);
// Output the oidc access token as a secret
core.setOutput('jf-oidc-token', oidcToken);
core.setOutput('oidc-token', oidcToken);

// Output the user from the oidc access token subject as a secret
let payload: JWTTokenData = this.decodeOidcToken(oidcToken);
let tokenUser: string = this.extractTokenUser(payload.sub);
// Mark the user as a secret
core.setSecret(tokenUser);
// Output the user from the oidc access token subject extracted from the last section of the subject
core.setOutput('jf-oidc-user', tokenUser);
core.setOutput('oidc-user', tokenUser);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ describe('extractTokenUser', () => {

describe('decodeOidcToken', () => {
it('should decode valid OIDC token', () => {
const oidcToken = Buffer.from(JSON.stringify({ sub: 'test' })).toString('base64') + '.eyJzdWIiOiJ0ZXN0In0.' + Buffer.from(JSON.stringify({ sub: 'test' })).toString('base64');
const oidcToken =
Buffer.from(JSON.stringify({ sub: 'test' })).toString('base64') +
'.eyJzdWIiOiJ0ZXN0In0.' +
Buffer.from(JSON.stringify({ sub: 'test' })).toString('base64');
const result = Utils.decodeOidcToken(oidcToken);
expect(result).toEqual({ sub: 'test' });
});
Expand All @@ -281,7 +284,10 @@ describe('decodeOidcToken', () => {
});

it('should throw error for OIDC token without subject', () => {
const oidcToken = Buffer.from(JSON.stringify({ notSub: 'test' })).toString('base64') + '.eyJub3RTdWIiOiJ0ZXN0In0.' + Buffer.from(JSON.stringify({ notSub: 'test' })).toString('base64');
const oidcToken =
Buffer.from(JSON.stringify({ notSub: 'test' })).toString('base64') +
'.eyJub3RTdWIiOiJ0ZXN0In0.' +
Buffer.from(JSON.stringify({ notSub: 'test' })).toString('base64');
expect(() => Utils.decodeOidcToken(oidcToken)).toThrowError('OIDC invalid access token format');
});
});
});

0 comments on commit a480950

Please sign in to comment.