-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAML: Parse and Validate AuthnRequest
ref DEV-1724
- Loading branch information
Showing
20 changed files
with
578 additions
and
15 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
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,9 @@ | ||
package saml | ||
|
||
import "github.com/authgear/authgear-server/pkg/lib/saml" | ||
|
||
type HandlerSAMLService interface { | ||
IdpMetadata(serviceProviderId string) (*saml.Metadata, error) | ||
ParseAuthnRequest(input []byte) (*saml.AuthnRequest, error) | ||
ValidateAuthnRequest(serviceProviderId string, authnRequest *saml.AuthnRequest) error | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
package saml | ||
|
||
import ( | ||
crewjamsaml "github.com/crewjam/saml" | ||
|
||
"github.com/authgear/authgear-server/pkg/lib/saml/binding" | ||
) | ||
|
||
type AuthnRequest struct { | ||
crewjamsaml.AuthnRequest | ||
} | ||
|
||
func (a *AuthnRequest) GetProtocolBinding() binding.SAMLBinding { | ||
return binding.SAMLBinding(a.AuthnRequest.ProtocolBinding) | ||
} |
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,26 @@ | ||
package binding | ||
|
||
import ( | ||
crewjamsaml "github.com/crewjam/saml" | ||
) | ||
|
||
type SAMLBinding string | ||
|
||
const ( | ||
SAMLBindingHTTPRedirect SAMLBinding = crewjamsaml.HTTPRedirectBinding | ||
SAMLBindingPostRedirect SAMLBinding = crewjamsaml.HTTPPostBinding | ||
) | ||
|
||
var SupportedBindings []SAMLBinding = []SAMLBinding{ | ||
SAMLBindingHTTPRedirect, | ||
SAMLBindingPostRedirect, | ||
} | ||
|
||
func (b SAMLBinding) IsSupported() bool { | ||
for _, supported := range SupportedBindings { | ||
if b == supported { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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,33 @@ | ||
// Copied from https://github.com/crewjam/saml/blob/8e9236867d176ad6338c870a84e2039aef8a5021/flate.go | ||
|
||
package binding | ||
|
||
import ( | ||
"compress/flate" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
const flateUncompressLimit = 10 * 1024 * 1024 // 10MB | ||
|
||
func NewSaferFlateReader(r io.Reader) io.ReadCloser { | ||
return &saferFlateReader{r: flate.NewReader(r)} | ||
} | ||
|
||
type saferFlateReader struct { | ||
r io.ReadCloser | ||
count int | ||
} | ||
|
||
func (r *saferFlateReader) Read(p []byte) (n int, err error) { | ||
if r.count+len(p) > flateUncompressLimit { | ||
return 0, fmt.Errorf("flate: uncompress limit exceeded (%d bytes)", flateUncompressLimit) | ||
} | ||
n, err = r.r.Read(p) | ||
r.count += n | ||
return n, err | ||
} | ||
|
||
func (r *saferFlateReader) Close() error { | ||
return r.r.Close() | ||
} |
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,6 @@ | ||
package saml | ||
|
||
const ( | ||
// https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf 3.2.2 | ||
SAMLVersion2 string = "2.0" | ||
) |
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,24 @@ | ||
package saml | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/authgear/authgear-server/pkg/util/rand" | ||
) | ||
|
||
const ( | ||
idAlphabet string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
) | ||
|
||
// It must start with a letter or underscore, and can only contain letters, digits, underscores, hyphens, and periods. | ||
// https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#ID | ||
// https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#NCName | ||
|
||
func generateID(prefix string) string { | ||
id := rand.StringWithAlphabet(32, idAlphabet, rand.SecureRand) | ||
return fmt.Sprintf("%s_%s", prefix, id) | ||
} | ||
|
||
func GenerateResponseID() string { | ||
return generateID("samlresponse") | ||
} |
File renamed without changes.
Oops, something went wrong.