1
1
version : ' 1.0'
2
2
kind : step-type
3
3
metadata :
4
- version : 1.0.1
4
+ version : 1.1.0
5
5
name : obtain-oidc-id-token
6
6
description : >-
7
7
Obtain ID token from Codefresh OIDC Provider
@@ -25,7 +25,7 @@ metadata:
25
25
url : https://raw.githubusercontent.com/codefresh-io/steps/master/incubating/obtain-oidc-id-token/icon.svg
26
26
background : ' #f4f4f4'
27
27
examples :
28
- - description : example-with-print-output
28
+ - description : example-basic
29
29
workflow :
30
30
version : ' 1.0'
31
31
steps :
@@ -38,6 +38,21 @@ metadata:
38
38
commands :
39
39
- echo $ID_TOKEN
40
40
- 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}}
41
56
- description : example-with-aws-sts-assume-role-step
42
57
workflow :
43
58
version : ' 1.0'
@@ -57,6 +72,21 @@ metadata:
57
72
commands :
58
73
- aws s3 ls "s3://bucket-name/"
59
74
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
+ }
60
90
returns : |-
61
91
{
62
92
"definitions": {},
@@ -78,8 +108,25 @@ spec:
78
108
main :
79
109
name : obtain-oidc-id-token
80
110
image : quay.io/curl/curl-base
111
+ environment :
112
+ - ' AUDIENCE=${{AUDIENCE}}'
81
113
commands :
82
114
- |
83
115
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
+
85
132
cf_export ID_TOKEN=$ID_TOKEN --mask
0 commit comments