Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ func (m *MockOIDC) Token(rw http.ResponseWriter, req *http.Request) {
}

func (m *MockOIDC) validateTokenParams(rw http.ResponseWriter, req *http.Request) bool {
if !assertPresence([]string{"client_id", "client_secret", "grant_type"}, rw, req) {
requiredParams := []string{"client_id", "grant_type"}
if !m.PublicClient {
requiredParams = append(requiredParams, "client_secret")
}

if !assertPresence(requiredParams, rw, req) {
return false
}

Expand All @@ -207,10 +212,13 @@ func (m *MockOIDC) validateTokenParams(rw http.ResponseWriter, req *http.Request
if !equal {
return false
}
equal = assertEqual("client_secret", m.ClientSecret,
InvalidClient, "Invalid client secret", rw, req)
if !equal {
return false

if !m.PublicClient {
equal = assertEqual("client_secret", m.ClientSecret,
InvalidClient, "Invalid client secret", rw, req)
if !equal {
return false
}
}

return true
Expand Down
11 changes: 10 additions & 1 deletion mockoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ var NowFunc = time.Now
type MockOIDC struct {
ClientID string
ClientSecret string
PublicClient bool

AccessTTL time.Duration
RefreshTTL time.Duration

CodeChallengeMethodsSupported []string

Hostname string

// Normally, these would be private. Expose them publicly for
// power users.
Server *http.Server
Expand Down Expand Up @@ -202,7 +205,13 @@ func (m *MockOIDC) Addr() string {
if m.tlsConfig != nil {
proto = "https"
}
return fmt.Sprintf("%s://%s", proto, m.Server.Addr)

hostname := m.Hostname
if hostname == "" {
hostname = m.Server.Addr
}

return fmt.Sprintf("%s://%s", proto, hostname)
}

// Issuer returns the OIDC Issuer that will be in `iss` token claims
Expand Down