Add BuildTokenURLForSite for subdomain OAuth flows
Subdomain-based OAuth providers (e.g. Zendesk) authenticate against a per-customer host, <subdomain>.zendesk.com, for both the authorize and the token endpoint. The subdomain is known at initiate but, unlike Datadog's region, the provider does not echo it back on the callback, so it must survive the round-trip another way. Carry the chosen site on the HMAC-signed OAuth state (OAuth2State.Site) and add a BuildTokenURLForSite closure, symmetric with the existing BuildAuthURLForSite, that builds the token URL from it at callback time. The state is signed, so a tampered site is rejected before use; the closure still re-validates the format. Datadog's domain-echo path is unchanged and a provider sets at most one of the two closures. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -49,6 +49,7 @@ func (r *Registry) ApplyOAuth2Defaults(p string, redirectURI string, c *connecto
|
||||
c.RequiresPKCE = reg.RequiresPKCE
|
||||
c.BuildAuthURLForSite = reg.BuildAuthURLForSite
|
||||
c.BuildTokenURLForDomain = reg.BuildTokenURLForDomain
|
||||
c.BuildTokenURLForSite = reg.BuildTokenURLForSite
|
||||
|
||||
// Deep copy ExtraAuthParams so per-connector mutations (e.g.
|
||||
// incremental auth, scope overrides) cannot alias back into the
|
||||
|
||||
@@ -68,6 +68,13 @@ type Registration struct {
|
||||
// domain the provider returns on the OAuth callback (multi-site
|
||||
// providers, e.g. Datadog). It MUST validate domain. Nil otherwise.
|
||||
BuildTokenURLForDomain func(domain string) (string, error)
|
||||
// BuildTokenURLForSite builds the token endpoint URL from the
|
||||
// per-customer site/subdomain carried in the signed OAuth state, for
|
||||
// multi-site providers whose token host the provider does NOT echo back
|
||||
// on the callback (e.g. Zendesk's <subdomain>.zendesk.com). It MUST
|
||||
// validate site. A provider sets at most one of BuildTokenURLForDomain /
|
||||
// BuildTokenURLForSite. Nil otherwise.
|
||||
BuildTokenURLForSite func(site string) (string, error)
|
||||
|
||||
// Protocol support / GraphQL surface.
|
||||
SupportsAPIKey bool
|
||||
|
||||
Reference in New Issue
Block a user