NefixEstrada / pongo

Pongo is a https://github.com/gorilla/sessions store wrapper for https://github.com/crewjam/saml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pongo

GoDoc

Pongo is a gorilla/sessions store wrapper for crewjam/saml

Usage

package main

import (
	"crypto/rsa"
	"crypto/tls"
	"crypto/x509"
	"fmt"
	"net/http"
	"net/url"

	"github.com/crewjam/saml/samlsp"
	"github.com/gorilla/sessions"
	"github.com/nefixestrada/pongo"
)

func hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello, %s!", samlsp.AttributeFromContext(r.Context(), "displayName"))
}

var store = sessions.NewCookieStore([]byte("secret"))

func main() {
	keyPair, err := tls.LoadX509KeyPair("myservice.cert", "myservice.key")
	if err != nil {
		panic(err) // TODO handle error
	}
	keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0])
	if err != nil {
		panic(err) // TODO handle error
	}

	idpMetadataURL, err := url.Parse("https://samltest.id/saml/idp")
	if err != nil {
		panic(err) // TODO handle error
	}

	rootURL, err := url.Parse("http://localhost:8000")
	if err != nil {
		panic(err) // TODO handle error
	}

	samlSP, _ := pongo.New(store, samlsp.Options{
		URL:            *rootURL,
		Key:            keyPair.PrivateKey.(*rsa.PrivateKey),
		Certificate:    keyPair.Leaf,
		IDPMetadataURL: idpMetadataURL,
	})
	app := http.HandlerFunc(hello)
	http.Handle("/hello", samlSP.RequireAccount(app))
	http.Handle("/saml/", samlSP)
	http.ListenAndServe(":8000", nil)
}

Why is the library named pongo?

https://en.wikipedia.org/wiki/Orangutan

About

Pongo is a https://github.com/gorilla/sessions store wrapper for https://github.com/crewjam/saml

License:GNU Affero General Public License v3.0


Languages

Language:Go 100.0%