Skip to content

Commit 841e83e

Browse files
committed
fix: incorporate review suggestions/requests
1 parent 0a9fd8c commit 841e83e

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

modules/dex/dex.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c Container) CreatePassword(
126126
) (err error) {
127127
apiClient, connCloser, err := c.createDexAPIClient(ctx)
128128
if err != nil {
129-
return fmt.Errorf("prepare Dex API client: %w", err)
129+
return fmt.Errorf("create Dex API client: %w", err)
130130
}
131131

132132
defer func() {
@@ -159,6 +159,8 @@ func (c Container) CreatePassword(
159159
},
160160
}
161161

162+
clear(req.Hash)
163+
162164
if _, err = apiClient.CreatePassword(ctx, apiReq); err != nil {
163165
return fmt.Errorf("create password in Dex: %w", err)
164166
}
@@ -169,15 +171,16 @@ func (c Container) CreatePassword(
169171
// OpenIDConfiguration returns the OpenID configuration for the Dex instance.
170172
// It retrieves the raw configuration, unmarshals it into an OpenIDConfiguration struct,
171173
// and returns any error that occurs during the process.
172-
func (c Container) OpenIDConfiguration(ctx context.Context) (cfg OpenIDConfiguration, err error) {
174+
func (c Container) OpenIDConfiguration(ctx context.Context) (OpenIDConfiguration, error) {
173175
rawCfg, err := c.RawOpenIDConfiguration(ctx)
174176
if err != nil {
175-
return cfg, err
177+
return OpenIDConfiguration{}, err
176178
}
177179

180+
var cfg OpenIDConfiguration
178181
err = json.Unmarshal(rawCfg, &cfg)
179182
if err != nil {
180-
return cfg, fmt.Errorf("unmarshal OpenID configuration: %w", err)
183+
return OpenIDConfiguration{}, fmt.Errorf("unmarshal OpenID configuration: %w", err)
181184
}
182185

183186
return cfg, nil
@@ -196,7 +199,7 @@ func (c Container) RawOpenIDConfiguration(ctx context.Context) (rawCfg []byte, e
196199

197200
req, err := http.NewRequestWithContext(ctx, http.MethodGet, httpEndpoint+"/.well-known/openid-configuration", http.NoBody)
198201
if err != nil {
199-
return nil, fmt.Errorf("prepare OIDC discovery requrest: %w", err)
202+
return nil, fmt.Errorf("create OIDC discovery request: %w", err)
200203
}
201204

202205
httpClient := c.Client
@@ -332,7 +335,7 @@ func patchEndpoint(original, newHost string) (patched string, err error) {
332335

333336
// randomSecret generates a random password for identities.
334337
// Based on https://pkg.go.dev/crypto/[email protected]#Text
335-
// Can be replaced as soon as testcontainers-go is updated to Go 1.24 or higher.
338+
// TODO: replace as soon as testcontainers-go is updated to Go 1.24 or higher.
336339
func randomSecret() string {
337340
// ⌈log₃₂ 2¹²⁸⌉ = 26 chars
338341
const (

modules/dex/openid.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
package dex
22

3+
// OpenIDConfiguration represents the OpenID Connect discovery document.
4+
// Every OIDC provider must provide a valid OpenIDConfiguration.
5+
// This struct contains all the necessary information for a client to interact with an OIDC provider - in this case, Dex.
36
type OpenIDConfiguration struct {
4-
Issuer string `json:"issuer,omitzero"`
5-
AuthorizationEndpoint string `json:"authorization_endpoint,omitzero"`
6-
TokenEndpoint string `json:"token_endpoint,omitzero"`
7-
JwksURI string `json:"jwks_uri,omitzero"`
8-
UserinfoEndpoint string `json:"userinfo_endpoint,omitzero"`
9-
DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint,omitzero"`
10-
IntrospectionEndpoint string `json:"introspection_endpoint,omitzero"`
11-
GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
12-
ResponseTypesSupported []string `json:"response_types_supported,omitempty"`
13-
SubjectTypesSupported []string `json:"subject_types_supported,omitempty"`
14-
IDTokenSigningAlgValues []string `json:"id_token_signing_alg_values_supported,omitempty"`
15-
CodeChallengeMethods []string `json:"code_challenge_methods_supported,omitempty"`
16-
ScopesSupported []string `json:"scopes_supported,omitempty"`
17-
TokenEndpointAuthMethods []string `json:"token_endpoint_auth_methods_supported,omitempty"`
18-
ClaimsSupported []string `json:"claims_supported,omitempty"`
7+
// Issuer - name of the issuer, typically http://localhost:5556
8+
Issuer string `json:"issuer,omitzero"`
9+
// AuthorizationEndpoint - endpoint for authorization requests
10+
AuthorizationEndpoint string `json:"authorization_endpoint,omitzero"`
11+
// TokenEndpoint - endpoint for token requests (e.g. when using client credentials)
12+
TokenEndpoint string `json:"token_endpoint,omitzero"`
13+
// JWKSURI - endpoint for JSON Web Key Set (JWKS) requests
14+
JWKSURI string `json:"jwks_uri,omitzero"`
15+
// UserInfoEndpoint - endpoint for user info requests
16+
UserinfoEndpoint string `json:"userinfo_endpoint,omitzero"`
17+
// DeviceAuthorizationEndpoint - endpoint for device authorization requests
18+
DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint,omitzero"`
19+
// IntrospectionEndpoint - endpoint for token introspection requests
20+
IntrospectionEndpoint string `json:"introspection_endpoint,omitzero"`
21+
// GrantTypesSupported - list of grant types this provider supports
22+
GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
23+
// ResponseTypesSupported - list of response types this provider supports
24+
ResponseTypesSupported []string `json:"response_types_supported,omitempty"`
25+
// SubjectTypesSupported - list of subject types this provider supports
26+
SubjectTypesSupported []string `json:"subject_types_supported,omitempty"`
27+
// IDTokenSigningAlgValues - list of signing algorithms this provider supports for ID tokens
28+
IDTokenSigningAlgValues []string `json:"id_token_signing_alg_values_supported,omitempty"`
29+
// CodeChallengeMethods - list of code challenge methods this provider supports
30+
CodeChallengeMethods []string `json:"code_challenge_methods_supported,omitempty"`
31+
// ScopesSupported - list of scopes this provider supports
32+
ScopesSupported []string `json:"scopes_supported,omitempty"`
33+
// TokenEndpointAuthMethods - list of token endpoint authentication methods this provider supports
34+
TokenEndpointAuthMethods []string `json:"token_endpoint_auth_methods_supported,omitempty"`
35+
// ClaimsSupported - list of claims this provider supports
36+
ClaimsSupported []string `json:"claims_supported,omitempty"`
1937
}

0 commit comments

Comments
 (0)