From ec2d4bfa48fea01ac22e0968185e5ae768e99e92 Mon Sep 17 00:00:00 2001 From: Dan Pantry Date: Mon, 13 Nov 2023 12:57:33 -0800 Subject: [PATCH] Add sentinel error if we cant find a SAML response --- cli/oauth2.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/oauth2.go b/cli/oauth2.go index dee77baa..e9d86249 100644 --- a/cli/oauth2.go +++ b/cli/oauth2.go @@ -19,6 +19,8 @@ import ( "golang.org/x/oauth2" ) +var ErrNoSAMLAssertion = errors.New("no saml assertion") + // stateBufSize is the size of the buffer used to generate the state parameter. // 43 is a magic number - It generates states that are not too short or long for Okta's validation. const stateBufSize = 43 @@ -231,12 +233,12 @@ func ExchangeWebSSOTokenForSAMLAssertion(ctx context.Context, client *http.Clien doc, _ := html.Parse(resp.Body) form, ok := FindFirstForm(doc) if !ok { - return nil, errors.New("could not find form") + return nil, ErrNoSAMLAssertion } saml, ok := form.Inputs["SAMLResponse"] if !ok { - return nil, errors.New("no SAML assertion") + return nil, ErrNoSAMLAssertion } return []byte(saml), nil