Skip to content

Commit 1efeae1

Browse files
appflowyclaude
andcommitted
fix: force AuthStyleInParams for Apple OAuth token exchange
Apple's /auth/token requires client_id and client_secret in the form body (the client_secret is itself a JWT). go-oidc's Endpoint() leaves AuthStyle as Unknown, which makes oauth2 probe AuthStyleInHeader first. Apple rejects the Basic-auth attempt AND invalidates the authorization code on that first call, so the subsequent AuthStyleInParams retry fails with "invalid_grant". Setting AuthStyleInParams on the endpoint skips the bad probe and goes directly to the form-body mode Apple wants. Also drop the long-standing oauth2.SetAuthURLParam("secret", ...) call: Apple expects client_secret, not secret, and the oauth2 library now adds the correct client_secret automatically when AuthStyleInParams is set. The explicit client_id override is equally redundant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d02cbe3 commit 1efeae1

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

internal/api/provider/apple.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ func NewAppleProvider(ctx context.Context, ext conf.OAuthProviderConfiguration,
102102
return nil, err
103103
}
104104

105+
// Apple's /auth/token requires client_id and client_secret in the form body
106+
// (client_secret is itself a JWT). go-oidc's Endpoint() returns AuthStyleUnknown,
107+
// which makes oauth2 probe AuthStyleInHeader first — Apple invalidates the code
108+
// on that first attempt, so the InParams retry fails with "invalid_grant".
109+
endpoint := oidcProvider.Endpoint()
110+
endpoint.AuthStyle = oauth2.AuthStyleInParams
111+
105112
return &AppleProvider{
106113
Config: &oauth2.Config{
107114
ClientID: ext.ClientID[0],
108115
ClientSecret: ext.Secret,
109-
Endpoint: oidcProvider.Endpoint(),
116+
Endpoint: endpoint,
110117
Scopes: []string{
111118
"email",
112119
"name",
@@ -119,12 +126,7 @@ func NewAppleProvider(ctx context.Context, ext conf.OAuthProviderConfiguration,
119126

120127
// GetOAuthToken returns the apple provider access token
121128
func (p AppleProvider) GetOAuthToken(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
122-
appleOpts := []oauth2.AuthCodeOption{
123-
oauth2.SetAuthURLParam("client_id", p.ClientID),
124-
oauth2.SetAuthURLParam("secret", p.ClientSecret),
125-
}
126-
appleOpts = append(appleOpts, opts...)
127-
return p.Exchange(context.Background(), code, appleOpts...)
129+
return p.Exchange(context.Background(), code, opts...)
128130
}
129131

130132
func (p AppleProvider) RequiresPKCE() bool {

0 commit comments

Comments
 (0)