Skip to content

Commit eae9d59

Browse files
feat: added support for custom audiences in OIDC id tokens (#659)
* feat: added support for custom audiences in OIDC id tokens
1 parent 6b9369a commit eae9d59

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

incubating/obtain-oidc-id-token/step.yaml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '1.0'
22
kind: step-type
33
metadata:
4-
version: 1.0.1
4+
version: 1.1.0
55
name: obtain-oidc-id-token
66
description: >-
77
Obtain ID token from Codefresh OIDC Provider
@@ -25,7 +25,7 @@ metadata:
2525
url: https://raw.githubusercontent.com/codefresh-io/steps/master/incubating/obtain-oidc-id-token/icon.svg
2626
background: '#f4f4f4'
2727
examples:
28-
- description: example-with-print-output
28+
- description: example-basic
2929
workflow:
3030
version: '1.0'
3131
steps:
@@ -38,6 +38,21 @@ metadata:
3838
commands:
3939
- echo $ID_TOKEN
4040
- echo ${{steps.obtain_id_token.output.ID_TOKEN}}
41+
- description: example-with-custom-audience
42+
workflow:
43+
version: '1.0'
44+
steps:
45+
obtain_id_token:
46+
title: Obtain ID Token
47+
type: obtain-oidc-id-token
48+
arguments:
49+
AUDIENCE: https://my-audience.com
50+
print_output:
51+
title: Printing output from previous step
52+
image: alpine
53+
commands:
54+
- echo $ID_TOKEN
55+
- echo ${{steps.obtain_id_token.output.ID_TOKEN}}
4156
- description: example-with-aws-sts-assume-role-step
4257
workflow:
4358
version: '1.0'
@@ -57,6 +72,21 @@ metadata:
5772
commands:
5873
- aws s3 ls "s3://bucket-name/"
5974
spec:
75+
arguments: |-
76+
{
77+
"definitions": {},
78+
"$schema": "http://json-schema.org/draft-07/schema#",
79+
"type": "object",
80+
"additionalProperties": false,
81+
"patterns": [],
82+
"required": [],
83+
"properties": {
84+
"AUDIENCE": {
85+
"type": "string",
86+
"description": "the audience of the ID token. For multiple audiences, use a comma-separated list. Defaults to the address of the Codefresh platform instance (For SaaS, https://g.codefresh.io)"
87+
}
88+
}
89+
}
6090
returns: |-
6191
{
6292
"definitions": {},
@@ -78,8 +108,25 @@ spec:
78108
main:
79109
name: obtain-oidc-id-token
80110
image: quay.io/curl/curl-base
111+
environment:
112+
- 'AUDIENCE=${{AUDIENCE}}'
81113
commands:
82114
- |
83115
apk add jq
84-
ID_TOKEN=$(curl -H "Authorization: $CF_OIDC_REQUEST_TOKEN" "$CF_OIDC_REQUEST_URL" | jq -r ".id_token")
116+
117+
URL="$CF_OIDC_REQUEST_URL"
118+
if [ -n "$AUDIENCE" ]; then
119+
ENCODED_AUDIENCE=$(echo -n "$AUDIENCE" | jq -s -R -r '@uri')
120+
URL="$URL?audience=$ENCODED_AUDIENCE"
121+
fi
122+
123+
RESPONSE=$(curl -H "Authorization: $CF_OIDC_REQUEST_TOKEN" "$URL")
124+
ID_TOKEN=$(echo "$RESPONSE" | jq -r ".id_token")
125+
126+
if [ -z "$ID_TOKEN" ] || [ "$ID_TOKEN" = "null" ]; then
127+
echo "Failed to obtain ID token; API response:"
128+
echo "$RESPONSE"
129+
exit 1
130+
fi
131+
85132
cf_export ID_TOKEN=$ID_TOKEN --mask

0 commit comments

Comments
 (0)