Skip to content

Commit 015330c

Browse files
feat: support custom token endpoint from service account credentials (#6277)
* feat: support custom token endpoint from service account credentials
1 parent b76dad3 commit 015330c

5 files changed

Lines changed: 43 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Release (2026-MM-DD)
2+
- `core`: [v0.26.0](core/CHANGELOG.md#v0260)
3+
- **Feature:** Added support for custom `TokenEndpoint` in service account credentials.
24
- `core`: [v0.25.0](core/CHANGELOG.md#v0250)
35
- Minimal go version is now Go 1.25
46
- `alb`:

core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.26.0
2+
- **Feature:** Added support for custom `TokenEndpoint` in service account credentials.
3+
14
## v0.25.0
25
- Minimal go version is now Go 1.25
36

core/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.25.0
1+
v0.26.0

core/clients/key_flow.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ type ServiceAccountKeyResponse struct {
7878
}
7979

8080
type ServiceAccountKeyCredentials struct {
81-
Aud string `json:"aud"`
82-
Iss string `json:"iss"`
83-
Kid string `json:"kid"`
84-
PrivateKey *string `json:"privateKey,omitempty"`
85-
Sub uuid.UUID `json:"sub"`
81+
Aud string `json:"aud"`
82+
Iss string `json:"iss"`
83+
Kid string `json:"kid"`
84+
PrivateKey *string `json:"privateKey,omitempty"`
85+
Sub uuid.UUID `json:"sub"`
86+
TokenEndpoint string `json:"tokenEndpoint"`
8687
}
8788

8889
// GetConfig returns the flow configuration
@@ -117,13 +118,26 @@ func (c *KeyFlow) GetToken() TokenResponseBody {
117118
return *c.token
118119
}
119120

121+
// getCredentialsTokenEndpoint returns the token endpoint from credentials or a default fallback
122+
func (cfg *KeyFlowConfig) getCredentialsTokenEndpoint() string {
123+
if cfg.ServiceAccountKey == nil || cfg.ServiceAccountKey.Credentials == nil {
124+
return tokenAPI
125+
}
126+
127+
if cfg.ServiceAccountKey.Credentials.TokenEndpoint == "" {
128+
return tokenAPI
129+
}
130+
131+
return cfg.ServiceAccountKey.Credentials.TokenEndpoint
132+
}
133+
120134
func (c *KeyFlow) Init(cfg *KeyFlowConfig) error {
121135
// No concurrency at this point, so no mutex check needed
122136
c.token = &TokenResponseBody{}
123137
c.config = cfg
124138

125139
if c.config.TokenUrl == "" {
126-
c.config.TokenUrl = tokenAPI
140+
c.config.TokenUrl = c.config.getCredentialsTokenEndpoint()
127141
}
128142

129143
c.tokenExpirationLeeway = defaultTokenExpirationLeeway

core/clients/key_flow_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ func TestKeyFlowInit(t *testing.T) {
7676
genPrivateKey bool
7777
invalidPrivateKey bool
7878
wantErr bool
79+
wantTokenUrl string
7980
}{
8081
{
8182
name: "ok-provided-private-key",
8283
serviceAccountKey: fixtureServiceAccountKey(),
8384
genPrivateKey: true,
8485
wantErr: false,
86+
wantTokenUrl: tokenAPI,
8587
},
8688
{
8789
name: "missing_private_key",
@@ -102,6 +104,15 @@ func TestKeyFlowInit(t *testing.T) {
102104
invalidPrivateKey: true,
103105
wantErr: true,
104106
},
107+
{
108+
name: "ok-custom-token-endpoint",
109+
serviceAccountKey: fixtureServiceAccountKey(func(s *ServiceAccountKeyResponse) {
110+
s.Credentials.TokenEndpoint = "https://custom.stackit.cloud/token"
111+
}),
112+
genPrivateKey: true,
113+
wantErr: false,
114+
wantTokenUrl: "https://custom.stackit.cloud/token",
115+
},
105116
}
106117
for _, tt := range tests {
107118
t.Run(tt.name, func(t *testing.T) {
@@ -126,6 +137,12 @@ func TestKeyFlowInit(t *testing.T) {
126137
if keyFlow.config == nil {
127138
t.Error("config is nil")
128139
}
140+
141+
if !tt.wantErr && tt.wantTokenUrl != "" {
142+
if keyFlow.config.TokenUrl != tt.wantTokenUrl {
143+
t.Errorf("KeyFlow.Init() TokenUrl = %v, wantTokenUrl %v", keyFlow.config.TokenUrl, tt.wantTokenUrl)
144+
}
145+
}
129146
})
130147
}
131148
}

0 commit comments

Comments
 (0)