Add DocuSign partner OAuth2 with PKCE and picker

DocuSign approved our partner integration, so the connector can now
complete a real OAuth2 authorization-code flow. The integration key
has PKCE enabled, so RequiresPKCE is set; the confidential grant still
authenticates the token exchange with Basic auth and replays the
verifier as the documented hardening layer.

A DocuSign user may have access to several accounts, so this replaces
the previous auto-default-account behavior with a Pattern-1 picker:
the user chooses the account after OAuth, the choice is stored on
DocuSignConnectorSettings, and the driver and name resolver resolve
the selected account's data-center base URI from /oauth/userinfo.

Other changes:
- Request the extended scope so the refresh token's 30-day window
  rolls on each use; without it the token hard-expires 30 days after
  consent and breaks the connection.
- Drop API-key support: DocuSign has no static API key, only OAuth.
- Return ("", nil) from the name resolver on terminal failures so the
  source-name worker does not retry a revoked token forever.
- Add a driver test and cassette; the test previously skipped in CI
  for lack of a cassette.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-06-08 23:17:18 +02:00
parent 474907e15c
commit baf9ca2fe9
8 changed files with 235 additions and 88 deletions

View File

@@ -513,54 +513,36 @@ func (r *hubspotNameResolver) ResolveInstanceName(ctx context.Context) (string,
return resp.AccountName, nil
}
// docusignNameResolver resolves the DocuSign account name from userinfo.
// docusignNameResolver resolves the configured DocuSign account's name from
// the OAuth2 userinfo endpoint, for the AccessReviewSource title.
type docusignNameResolver struct {
httpClient *http.Client
accountID string
}
func NewDocuSignNameResolver(httpClient *http.Client) NameResolver {
return &docusignNameResolver{httpClient: httpClient}
func NewDocuSignNameResolver(httpClient *http.Client, accountID string) NameResolver {
return &docusignNameResolver{httpClient: httpClient, accountID: accountID}
}
func (r *docusignNameResolver) ResolveInstanceName(ctx context.Context) (string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, docusignUserInfoEndpoint, nil)
accounts, err := fetchDocuSignAccounts(ctx, r.httpClient)
if err != nil {
return "", fmt.Errorf("cannot create docusign userinfo request: %w", err)
// A dead token (non-2xx) is terminal: the source-name worker marks
// the source synced on ("", nil), so it stops retrying. Transient and
// decode failures stay errors so the worker retries.
if errors.Is(err, errDocuSignUserInfoStatus) {
return "", nil
}
return "", err
}
req.Header.Set("Accept", "application/json")
httpResp, err := r.httpClient.Do(req)
if err != nil {
return "", fmt.Errorf("cannot execute docusign userinfo request: %w", err)
}
defer func() { _ = httpResp.Body.Close() }()
if httpResp.StatusCode < 200 || httpResp.StatusCode >= 300 {
return "", fmt.Errorf("cannot fetch docusign userinfo: unexpected status %d", httpResp.StatusCode)
}
var resp struct {
Accounts []struct {
AccountName string `json:"account_name"`
IsDefault bool `json:"is_default"`
} `json:"accounts"`
}
if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil {
return "", fmt.Errorf("cannot decode docusign userinfo response: %w", err)
}
for _, account := range resp.Accounts {
if account.IsDefault {
for _, account := range accounts {
if account.AccountID == r.accountID {
return account.AccountName, nil
}
}
if len(resp.Accounts) > 0 {
return resp.Accounts[0].AccountName, nil
}
return "", nil
}