Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exported function to Build the Authentication URL For HTTP GET… #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.test
.idea
15 changes: 12 additions & 3 deletions build_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,29 @@ func (sp *SAMLServiceProvider) BuildAuthBodyPostFromDocument(relayState string,
return sp.buildAuthBodyPostFromDocument(relayState, doc)
}

// BuildAuthURL builds redirect URL to be sent to principal
func (sp *SAMLServiceProvider) BuildAuthURL(relayState string) (string, error) {
// BuildAuthURLWithPost builds redirect URL to be sent to principal
func (sp *SAMLServiceProvider) BuildAuthURLWithPost(relayState string) (string, error) {
doc, err := sp.BuildAuthRequestDocument()
if err != nil {
return "", err
}
return sp.BuildAuthURLFromDocument(relayState, doc)
}

// BuildAuthURLWithRedirect builds redirect URL to be sent to principal with the HTTP Redirect Binding
func (sp *SAMLServiceProvider) BuildAuthURLWithRedirect(relayState string) (string, error) {
doc, err := sp.BuildAuthRequestDocument()
if err != nil {
return "", err
}
return sp.BuildAuthURLRedirect(relayState, doc)
}

// AuthRedirect takes a ResponseWriter and Request from an http interaction and
// redirects to the SAMLServiceProvider's configured IdP, including the
// relayState provided, if any.
func (sp *SAMLServiceProvider) AuthRedirect(w http.ResponseWriter, r *http.Request, relayState string) (err error) {
url, err := sp.BuildAuthURL(relayState)
url, err := sp.BuildAuthURLWithPost(relayState)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion s2example/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func main() {
})

println("Visit this URL To Authenticate:")
authURL, err := sp.BuildAuthURL("")
authURL, err := sp.BuildAuthURLWithPost("")
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion saml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestSAML(t *testing.T) {
NameIdFormat: NameIdFormatPersistent,
}

authRequestURL, err := sp.BuildAuthURL("/some/link/here")
authRequestURL, err := sp.BuildAuthURLWithPost("/some/link/here")
require.NoError(t, err)
require.NotEmpty(t, authRequestURL)

Expand Down