Skip to content

Commit

Permalink
Add sentinel error if we cant find a SAML response
Browse files Browse the repository at this point in the history
  • Loading branch information
punmechanic committed Nov 13, 2023
1 parent 7c2fb08 commit ec2d4bf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cli/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec2d4bf

Please sign in to comment.