Skip to content

Commit 0ab422d

Browse files
committed
add scopes config variable
1 parent a640010 commit 0ab422d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package oauth
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67

78
"github.com/tuannvm/oauth-mcp-proxy/provider"
89
)
@@ -19,6 +20,7 @@ type Config struct {
1920
Audience string
2021
ClientID string
2122
ClientSecret string
23+
Scopes []string
2224

2325
// Server configuration
2426
ServerURL string // Full URL of the MCP server
@@ -226,6 +228,12 @@ func (b *ConfigBuilder) WithJWTSecret(secret []byte) *ConfigBuilder {
226228
return b
227229
}
228230

231+
// WithScopes sets the OIDC scopes
232+
func (b *ConfigBuilder) WithScopes(scopes []string) *ConfigBuilder {
233+
b.config.Scopes = scopes
234+
return b
235+
}
236+
229237
// WithLogger sets the logger
230238
func (b *ConfigBuilder) WithLogger(logger Logger) *ConfigBuilder {
231239
b.config.Logger = logger
@@ -307,6 +315,7 @@ func FromEnv() (*Config, error) {
307315
}
308316

309317
jwtSecret := getEnv("JWT_SECRET", "")
318+
scopes := strings.Split(getEnv("OIDC_SCOPES", ""), " ")
310319

311320
return NewConfigBuilder().
312321
WithMode(getEnv("OAUTH_MODE", "")).
@@ -316,6 +325,7 @@ func FromEnv() (*Config, error) {
316325
WithAudience(getEnv("OIDC_AUDIENCE", "")).
317326
WithClientID(getEnv("OIDC_CLIENT_ID", "")).
318327
WithClientSecret(getEnv("OIDC_CLIENT_SECRET", "")).
328+
WithScopes(scopes).
319329
WithSkipAudienceCheck(parseBoolEnv("OIDC_SKIP_AUDIENCE_CHECK", false)).
320330
WithSkipIssuerCheck(parseBoolEnv("OIDC_SKIP_ISSUER_CHECK", false)).
321331
WithSkipExpiryCheck(parseBoolEnv("OIDC_SKIP_EXPIRY_CHECK", false)).

handlers.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type OAuth2Config struct {
4646
Audience string
4747
ClientID string
4848
ClientSecret string
49+
Scopes []string
4950

5051
// Server configuration
5152
MCPHost string
@@ -96,7 +97,7 @@ func NewOAuth2Handler(cfg *OAuth2Config, logger Logger) *OAuth2Handler {
9697
ClientID: cfg.ClientID,
9798
ClientSecret: cfg.ClientSecret,
9899
Endpoint: endpoint,
99-
Scopes: []string{"openid", "profile", "email"},
100+
Scopes: cfg.Scopes,
100101
}
101102

102103
// Log client configuration type for debugging
@@ -177,6 +178,11 @@ func NewOAuth2ConfigFromConfig(cfg *Config, version string) *OAuth2Config {
177178
mcpURL = getEnv("MCP_URL", fmt.Sprintf("%s://%s:%s", scheme, mcpHost, mcpPort))
178179
}
179180

181+
scopes := cfg.Scopes
182+
if len(scopes) == 0 {
183+
scopes = []string{"openid", "profile", "email"}
184+
}
185+
180186
return &OAuth2Config{
181187
Enabled: true,
182188
Mode: cfg.Mode,
@@ -186,6 +192,7 @@ func NewOAuth2ConfigFromConfig(cfg *Config, version string) *OAuth2Config {
186192
Audience: cfg.Audience,
187193
ClientID: cfg.ClientID,
188194
ClientSecret: cfg.ClientSecret,
195+
Scopes: scopes,
189196
MCPHost: mcpHost,
190197
MCPPort: mcpPort,
191198
MCPURL: mcpURL,

metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (h *OAuth2Handler) HandleOIDCDiscovery(w http.ResponseWriter, r *http.Reque
242242
"token_endpoint_auth_methods_supported": []string{"none"},
243243
"code_challenge_methods_supported": []string{"plain", "S256"},
244244
"subject_types_supported": []string{"public"},
245-
"scopes_supported": []string{"openid", "profile", "email"},
245+
"scopes_supported": h.config.Scopes,
246246
}
247247

248248
// Add provider-specific fields

0 commit comments

Comments
 (0)