Refactor app, implement logout

This commit is contained in:
Jan Dittberner 2020-12-31 13:19:21 +01:00
parent ce1fac0e68
commit 27e225795c
14 changed files with 647 additions and 349 deletions

51
common/services/oidc.go Normal file
View file

@ -0,0 +1,51 @@
package services
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
log "github.com/sirupsen/logrus"
)
type OpenIDConfiguration struct {
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
JwksUri string `json:"jwks_uri"`
EndSessionEndpoint string `json:"end_session_endpoint"`
}
func DiscoverOIDC(logger *log.Logger, oidcServer string, apiClient *http.Client) (o *OpenIDConfiguration, err error) {
var discoveryUrl *url.URL
if discoveryUrl, err = url.Parse(oidcServer); err != nil {
logger.Fatalf("could not parse oidc.server parameter value %s: %s", oidcServer, err)
} else {
discoveryUrl.Path = "/.well-known/openid-configuration"
}
var body []byte
var req *http.Request
req, err = http.NewRequest(http.MethodGet, discoveryUrl.String(), bytes.NewBuffer(body))
if err != nil {
return
}
req.Header = map[string][]string{
"Accept": {"application/json"},
}
resp, err := apiClient.Do(req)
if err != nil {
return
}
dec := json.NewDecoder(resp.Body)
o = &OpenIDConfiguration{}
err = dec.Decode(o)
if err != nil {
return
}
return
}

View file

@ -0,0 +1,19 @@
package services
import (
"crypto/rand"
log "github.com/sirupsen/logrus"
)
func GenerateKey(length int) []byte {
key := make([]byte, length)
read, err := rand.Read(key)
if err != nil {
log.Fatalf("could not generate key: %s", err)
}
if read != length {
log.Fatalf("read %d bytes, expected %d bytes", read, length)
}
return key
}