11package main
22
33import (
4+ "context"
5+ "crypto/rsa"
6+ "crypto/tls"
7+ "crypto/x509"
48 "fmt"
59 "net/http"
610 "net/url"
711
8- "crypto/tls"
9- "crypto/x509"
10-
11- "crypto/rsa"
12-
1312 "github.com/crewjam/saml/samlsp"
1413)
1514
1615func hello (w http.ResponseWriter , r * http.Request ) {
17- fmt .Fprintf (w , "Hello, %s!" , samlsp .Token (r .Context ()). Attributes . Get ( "cn" ))
16+ fmt .Fprintf (w , "Hello, %s!" , samlsp .AttributeFromContext (r .Context (), "cn" ))
1817}
1918
2019func main () {
@@ -27,22 +26,21 @@ func main() {
2726 panic (err ) // TODO handle error
2827 }
2928
30- idpMetadataURL , err := url .Parse ("https://www.testshib.org/metadata/testshib-providers.xml" )
31- if err != nil {
32- panic (err ) // TODO handle error
33- }
29+ rootURL , _ := url .Parse ("http://localhost:8000" )
30+ idpMetadataURL , _ := url .Parse ("https://www.testshib.org/metadata/testshib-providers.xml" )
3431
35- rootURL , err := url . Parse ( "http://localhost:8000" )
36- if err != nil {
37- panic ( err ) // TODO handle error
38- }
32+ idpMetadata , err := samlsp . FetchMetadata (
33+ context . Background (),
34+ http . DefaultClient ,
35+ * idpMetadataURL )
3936
40- samlSP , _ := samlsp .New (samlsp.Options {
41- IDPMetadataURL : idpMetadataURL ,
42- URL : * rootURL ,
43- Key : keyPair .PrivateKey .(* rsa.PrivateKey ),
44- Certificate : keyPair .Leaf ,
37+ samlSP , err := samlsp .New (samlsp.Options {
38+ URL : * rootURL ,
39+ IDPMetadata : idpMetadata ,
40+ Key : keyPair .PrivateKey .(* rsa.PrivateKey ),
41+ Certificate : keyPair .Leaf ,
4542 })
43+
4644 app := http .HandlerFunc (hello )
4745 http .Handle ("/hello" , samlSP .RequireAccount (app ))
4846 http .Handle ("/saml/" , samlSP )
0 commit comments