Skip to content

Commit

Permalink
internal: recognize Salesforce and Okta domains as broken providers
Browse files Browse the repository at this point in the history
Fixes #166

Change-Id: Ib3854db4a28a596af3565a84843fc0fa66709193
Reviewed-on: https://go-review.googlesource.com/38376
Reviewed-by: Jaana Burcu Dogan <jbd@google.com>
  • Loading branch information
ericchiang authored and rakyll committed Mar 21, 2017
1 parent 30fcca6 commit 7374b3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ var brokenAuthHeaderProviders = []string{
"https://sandbox.codeswholesale.com/oauth/token",
}

// brokenAuthHeaderDomains lists broken providers that issue dynamic endpoints.
var brokenAuthHeaderDomains = []string{
".force.com",
".okta.com",
".oktapreview.com",
}

func RegisterBrokenAuthHeaderProvider(tokenURL string) {
brokenAuthHeaderProviders = append(brokenAuthHeaderProviders, tokenURL)
}
Expand All @@ -142,6 +149,14 @@ func providerAuthHeaderWorks(tokenURL string) bool {
}
}

if u, err := url.Parse(tokenURL); err == nil {
for _, s := range brokenAuthHeaderDomains {
if strings.HasSuffix(u.Host, s) {
return false
}
}
}

// Assume the provider implements the spec properly
// otherwise. We can add more exceptions as they're
// discovered. We will _not_ be adding configurable hooks
Expand Down
21 changes: 21 additions & 0 deletions internal/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,24 @@ func Test_providerAuthHeaderWorks(t *testing.T) {
t.Errorf("got %q as unbroken; want broken", p)
}
}

func TestProviderAuthHeaderWorksDomain(t *testing.T) {
tests := []struct {
tokenURL string
wantWorks bool
}{
{"https://dev-12345.okta.com/token-url", false},
{"https://dev-12345.oktapreview.com/token-url", false},
{"https://dev-12345.okta.org/token-url", true},
{"https://foo.bar.force.com/token-url", false},
{"https://foo.force.com/token-url", false},
{"https://force.com/token-url", true},
}

for _, test := range tests {
got := providerAuthHeaderWorks(test.tokenURL)
if got != test.wantWorks {
t.Errorf("providerAuthHeaderWorks(%q) = %v; want %v", test.tokenURL, got, test.wantWorks)
}
}
}

0 comments on commit 7374b3f

Please sign in to comment.