forked from crewjam/saml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper to parse redirect AuthnRequests
This makes test expectations easier to manage. Before this we compared against the flats-compressed and base64-encoded request, which does ensure that we produce compatible requests, but which makes changing the expectations hard to manage.
- Loading branch information
Showing
4 changed files
with
53 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package testsaml | ||
|
||
import ( | ||
"bytes" | ||
"compress/flate" | ||
"encoding/base64" | ||
"fmt" | ||
"io/ioutil" | ||
"net/url" | ||
) | ||
|
||
// ParseRedirectRequest returns the decoded SAML AuthnRequest from an HTTP-Redirect URL | ||
func ParseRedirectRequest(u *url.URL) ([]byte, error) { | ||
compressedRequest, err := base64.StdEncoding.DecodeString(u.Query().Get("SAMLRequest")) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot decode request: %s", err) | ||
} | ||
buf, err := ioutil.ReadAll(flate.NewReader(bytes.NewReader(compressedRequest))) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot decompress request: %s", err) | ||
} | ||
return buf, nil | ||
} |