-
Notifications
You must be signed in to change notification settings - Fork 475
Expand file tree
/
Copy pathidp.go
More file actions
49 lines (41 loc) · 1.15 KB
/
Copy pathidp.go
File metadata and controls
49 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Package main contains an example identity provider implementation.
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"net/http"
"net/url"
"github.com/crewjam/saml/logger"
"github.com/crewjam/saml/samlidp"
)
func main() {
logr := logger.DefaultLogger
baseURLstr := flag.String("idp", "http://localhost:8080", "The URL to the IDP")
certFile := flag.String("cert", "idp.cert", "The certificate file path")
keyFile := flag.String("key", "idp.key", "The private key file path")
flag.Parse()
baseURL, err := url.Parse(*baseURLstr)
if err != nil {
logr.Fatalf("cannot parse base URL: %v", err)
}
keyPair, err := tls.LoadX509KeyPair(*certFile, *keyFile)
if err != nil {
logr.Fatalf("cannot load key pair: %v", err)
}
keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0])
if err != nil {
logr.Fatalf("cannot parse certificate: %v", err)
}
idpServer, err := samlidp.New(samlidp.Options{
URL: *baseURL,
Key: keyPair.PrivateKey,
Logger: logr,
Certificate: keyPair.Leaf,
Store: &samlidp.MemoryStore{},
})
if err != nil {
logr.Fatalf("%s", err)
}
http.ListenAndServe(":8080", idpServer)
}