This commit is contained in:
Livio Amstutz 2019-11-29 15:03:13 +01:00
parent 18a17e1b94
commit caedc72d45
11 changed files with 383 additions and 52 deletions

View file

@ -2,10 +2,7 @@ package op
import (
"context"
"errors"
"net/http"
"net/url"
"strings"
"github.com/gorilla/mux"
@ -25,28 +22,6 @@ type OpenIDProvider interface {
HttpHandler() *http.Server
}
func ValidateIssuer(issuer string) error {
if issuer == "" {
return errors.New("missing issuer")
}
u, err := url.Parse(issuer)
if err != nil {
return errors.New("invalid url for issuer")
}
if u.Host == "" {
return errors.New("host for issuer missing")
}
if u.Scheme != "https" {
if !(u.Scheme == "http" && (u.Host == "localhost" || u.Host == "127.0.0.1" || u.Host == "::1" || strings.HasPrefix(u.Host, "localhost:"))) { //TODO: ?
return errors.New("scheme for issuer must be `https`")
}
}
if u.Fragment != "" || len(u.Query()) > 0 {
return errors.New("no fragments or query allowed for issuer")
}
return nil
}
func CreateRouter(o OpenIDProvider) *mux.Router {
router := mux.NewRouter()
router.HandleFunc(oidc.DiscoveryEndpoint, o.HandleDiscovery)