Rename access-review migration with random time → Validate PagerDuty subdomain on OAuth callback

- Rename access-review migration with random time
- Move PagerDuty token-response handling to its own file
- Strip OAuth error_description from log and redirect
- Validate PagerDuty subdomain on OAuth callback

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-05-17 17:22:49 +02:00
parent 842f9cfbc5
commit caec9f1ad5
4 changed files with 120 additions and 28 deletions

View File

@@ -331,29 +331,11 @@ func (c *OAuth2Connector) CompleteWithState(ctx context.Context, r *http.Request
return conn, &payload.Data, err
}
// PagerDuty Scoped OAuth includes the customer's subdomain in the
// token response body. We parse it here so the OAuth callback
// handler can write it to PagerDutyConnectorSettings without
// having to issue a second decode against a now-closed body.
if payload.Data.Provider == PagerDutyProvider {
var pd struct {
Subdomain string `json:"subdomain"`
}
if err := json.Unmarshal(body, &pd); err == nil && pd.Subdomain != "" {
if payload.Data.ProviderMetadata == nil {
payload.Data.ProviderMetadata = map[string]string{}
}
payload.Data.ProviderMetadata["subdomain"] = pd.Subdomain
}
}
AbsorbPagerDutyTokenResponse(&payload.Data, body)
return &oauth2Conn, &payload.Data, nil
}
// PagerDutyProvider is the canonical string used by PagerDuty in the
// state token's `provider` field.
const PagerDutyProvider = "PAGERDUTY"
func basicAuthHeader(clientID, clientSecret string) string {
credentials := clientID + ":" + clientSecret
return "Basic " + base64.StdEncoding.EncodeToString([]byte(credentials))
@@ -425,6 +407,12 @@ func (c *OAuth2Connector) buildTokenRequest(ctx context.Context, code, redirectU
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "Probo Connector")
req.Header.Set("Authorization", basicAuthHeader(c.ClientID, c.ClientSecret))
// Deel rejects token-exchange requests that omit the x-client-id
// header even when the credentials are correctly Base64-encoded
// in the Authorization header. Sending it for every basic-form
// provider is harmless — providers that don't expect it ignore
// the header.
req.Header.Set("x-client-id", c.ClientID)
return req, nil
default: