Skip to content

Commit 604c9f0

Browse files
committed
Fixes
1 parent a9c123b commit 604c9f0

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

integration/config/config.oauth-token-test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"displayName": "Notion",
3030
"instructions": "Create a Notion integration token",
3131
"helpUrl": "https://developers.notion.com",
32-
"tokenFormat": "^secret_[a-zA-Z0-9]{43}$"
32+
"validation": "^secret_[a-zA-Z0-9]{43}$"
3333
}
3434
},
3535
"github": {

internal/auth/server.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,37 @@ func NewServer(config Config, store storage.Storage) (*Server, error) {
100100

101101
// Configure fosite
102102
oauthConfig := &compose.Config{
103-
AccessTokenLifespan: config.TokenTTL,
104-
RefreshTokenLifespan: config.TokenTTL * 2,
105-
AuthorizeCodeLifespan: 10 * time.Minute,
106-
MinParameterEntropy: minEntropy,
107-
EnforcePKCE: true,
108-
ScopeStrategy: fosite.HierarchicScopeStrategy,
109-
AudienceMatchingStrategy: fosite.DefaultAudienceMatchingStrategy,
110-
HashCost: 12,
103+
AccessTokenLifespan: config.TokenTTL,
104+
RefreshTokenLifespan: config.TokenTTL * 2,
105+
AuthorizeCodeLifespan: 10 * time.Minute,
106+
TokenURL: config.Issuer + "/token",
107+
ScopeStrategy: fosite.HierarchicScopeStrategy,
108+
AudienceMatchingStrategy: fosite.DefaultAudienceMatchingStrategy,
109+
EnforcePKCEForPublicClients: true,
110+
EnablePKCEPlainChallengeMethod: false,
111+
MinParameterEntropy: minEntropy,
111112
}
112113

113-
// Create provider using compose
114-
provider := compose.ComposeAllEnabled(
114+
// Create provider using compose with specific factories
115+
provider := compose.Compose(
115116
oauthConfig,
116117
store,
117-
secret,
118-
nil, // RSA key not needed for our use case
118+
&compose.CommonStrategy{
119+
CoreStrategy: compose.NewOAuth2HMACStrategy(oauthConfig, secret, nil),
120+
},
121+
nil, // hasher
122+
compose.OAuth2AuthorizeExplicitFactory,
123+
compose.OAuth2ClientCredentialsGrantFactory,
124+
compose.OAuth2PKCEFactory,
125+
compose.OAuth2RefreshTokenGrantFactory,
126+
compose.OAuth2TokenIntrospectionFactory,
119127
)
120128

129+
// Set default session duration if not configured
130+
if config.SessionDuration == 0 {
131+
config.SessionDuration = 24 * time.Hour
132+
}
133+
121134
return &Server{
122135
provider: provider,
123136
storage: store,

internal/server/auth_handlers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ func (h *AuthHandlers) AuthorizeHandler(w http.ResponseWriter, r *http.Request)
7575
ctx := r.Context()
7676
log.Logf("Authorize handler called: %s %s", r.Method, r.URL.Path)
7777

78+
// In development mode, generate a secure state parameter if missing
79+
// This works around bugs in OAuth clients that don't send state
80+
stateParam := r.URL.Query().Get("state")
81+
if internal.IsDevelopmentMode() && len(stateParam) == 0 {
82+
generatedState := crypto.GenerateSecureToken()
83+
log.LogWarn("Development mode: generating state parameter '%s' for buggy client", generatedState)
84+
q := r.URL.Query()
85+
q.Set("state", generatedState)
86+
r.URL.RawQuery = q.Encode()
87+
// Also update the form values
88+
if r.Form == nil {
89+
_ = r.ParseForm()
90+
}
91+
r.Form.Set("state", generatedState)
92+
}
93+
7894
// Parse the authorize request
7995
ar, err := h.authServer.GetProvider().NewAuthorizeRequest(ctx, r)
8096
if err != nil {

0 commit comments

Comments
 (0)