MCPcopy Create free account
hub / github.com/crewjam/saml / main

Function main

example/service.go:102–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100)
101
102func main() {
103 rootURLstr := flag.String("url", "https://962766ce.ngrok.io", "The base URL of this service")
104 idpMetadataURLstr := flag.String("idp", "https://516becc2.ngrok.io/metadata", "The metadata URL for the IDP")
105 flag.Parse()
106
107 keyPair, err := tls.X509KeyPair(cert, key)
108 if err != nil {
109 panic(err) // TODO handle error
110 }
111 keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0])
112 if err != nil {
113 panic(err) // TODO handle error
114 }
115
116 idpMetadataURL, err := url.Parse(*idpMetadataURLstr)
117 if err != nil {
118 panic(err) // TODO handle error
119 }
120
121 idpMetadata, err := samlsp.FetchMetadata(context.Background(), http.DefaultClient,
122 *idpMetadataURL)
123 if err != nil {
124 panic(err) // TODO handle error
125 }
126
127 rootURL, err := url.Parse(*rootURLstr)
128 if err != nil {
129 panic(err) // TODO handle error
130 }
131
132 samlSP, err := samlsp.New(samlsp.Options{
133 URL: *rootURL,
134 Key: keyPair.PrivateKey.(*rsa.PrivateKey),
135 Certificate: keyPair.Leaf,
136 AllowIDPInitiated: true,
137 IDPMetadata: idpMetadata,
138 })
139 if err != nil {
140 panic(err) // TODO handle error
141 }
142
143 // register with the service provider
144 spMetadataBuf, _ := xml.MarshalIndent(samlSP.ServiceProvider.Metadata(), "", " ")
145
146 spURL := *idpMetadataURL
147 spURL.Path = "/services/sp"
148 http.Post(spURL.String(), "text/xml", bytes.NewReader(spMetadataBuf))
149
150 goji.Handle("/saml/*", samlSP)
151
152 authMux := web.New()
153 authMux.Use(samlSP.RequireAccount)
154 authMux.Get("/whoami", func(w http.ResponseWriter, r *http.Request) {
155 pretty.Fprintf(w, "%# v", r)
156 })
157 authMux.Post("/", CreateLink)
158 authMux.Get("/", ListLinks)
159

Callers

nothing calls this directly

Calls 7

FetchMetadataFunction · 0.92
NewFunction · 0.92
StringMethod · 0.80
NewMethod · 0.65
GetMethod · 0.65
MetadataMethod · 0.45
PostMethod · 0.45

Tested by

no test coverage detected