- 
                Notifications
    You must be signed in to change notification settings 
- Fork 472
refactor SAML SP #230
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
refactor SAML SP #230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| package main | ||
|  | ||
| import ( | ||
| "context" | ||
| "crypto/rsa" | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|  | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
|  | ||
| "crypto/rsa" | ||
|  | ||
| "github.com/crewjam/saml/samlsp" | ||
| ) | ||
|  | ||
| func hello(w http.ResponseWriter, r *http.Request) { | ||
| fmt.Fprintf(w, "Hello, %s!", samlsp.Token(r.Context()).Attributes.Get("cn")) | ||
| fmt.Fprintf(w, "Hello, %s!", samlsp.AttributeFromContext(r.Context(), "cn")) | ||
| } | ||
|  | ||
| func main() { | ||
|  | @@ -27,22 +26,27 @@ func main() { | |
| panic(err) // TODO handle error | ||
| } | ||
|  | ||
| idpMetadataURL, err := url.Parse("https://www.testshib.org/metadata/testshib-providers.xml") | ||
| rootURL, _ := url.Parse("http://localhost:8000") | ||
| idpMetadataURL, _ := url.Parse("https://www.testshib.org/metadata/testshib-providers.xml") | ||
|  | ||
| idpMetadata, err := samlsp.FetchMetadata( | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, either add an error handling or skip error checking like above - preferably option 1. | ||
| context.Background(), | ||
| http.DefaultClient, | ||
| *idpMetadataURL) | ||
| if err != nil { | ||
| panic(err) // TODO handle error | ||
| } | ||
|  | ||
| rootURL, err := url.Parse("http://localhost:8000") | ||
| samlSP, err := samlsp.New(samlsp.Options{ | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto on  | ||
| URL: *rootURL, | ||
| IDPMetadata: idpMetadata, | ||
| Key: keyPair.PrivateKey.(*rsa.PrivateKey), | ||
| Certificate: keyPair.Leaf, | ||
| }) | ||
| if err != nil { | ||
| panic(err) // TODO handle error | ||
| } | ||
|  | ||
| samlSP, _ := samlsp.New(samlsp.Options{ | ||
| IDPMetadataURL: idpMetadataURL, | ||
| URL: *rootURL, | ||
| Key: keyPair.PrivateKey.(*rsa.PrivateKey), | ||
| Certificate: keyPair.Leaf, | ||
| }) | ||
| app := http.HandlerFunc(hello) | ||
| http.Handle("/hello", samlSP.RequireAccount(app)) | ||
| http.Handle("/saml/", samlSP) | ||
|  | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's missing an error handling here (
if err != nil { panic(err) //TODO handle error})