aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--config.go9
-rw-r--r--main.go4
-rw-r--r--oidc.go42
3 files changed, 36 insertions, 19 deletions
diff --git a/config.go b/config.go
index 589627c..15d195a 100644
--- a/config.go
+++ b/config.go
@@ -77,10 +77,13 @@ var config struct {
}
}
-func fbfp_get_config(path string) {
+func fbfp_get_config(path string) error {
f := er(os.Open(path))
- e(scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers))
+ err := scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers)
+ if err != nil {
+ return err
+ }
/*
* TODO: We segfault when there are missing configuration options.
@@ -102,4 +105,6 @@ func fbfp_get_config(path string) {
config.Openid.Authorize =
*(config_with_pointers.Openid.Authorize)
}
+
+ return nil
}
diff --git a/main.go b/main.go
index 907ab26..a3fad41 100644
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ func main() {
*/
var err error
- fbfp_get_config("fbfp.scfg")
+ e(fbfp_get_config("fbfp.scfg"))
log.Printf("Setting up database\n")
e(setup_database())
@@ -58,7 +58,7 @@ func main() {
http.HandleFunc("/oidc", handle_oidc)
log.Printf("Fetching OpenID Connect configuration\n")
- get_openid_config(config.Openid.Endpoint)
+ e(get_openid_config(config.Openid.Endpoint))
log.Printf(
"Establishing listener for net \"%s\", addr \"%s\"\n",
diff --git a/oidc.go b/oidc.go
index 004efdd..c9d0d76 100644
--- a/oidc.go
+++ b/oidc.go
@@ -26,7 +26,6 @@ import (
"errors"
"fmt"
"io"
- "log"
"net/http"
"github.com/MicahParks/keyfunc/v3"
@@ -59,24 +58,29 @@ type msclaims_t struct {
* - https://login.microsoftonline.com/common
* - https://accounts.google.com/.well-known/openid-configuration
*/
-func get_openid_config(endpoint string) {
- resp := er(http.Get(endpoint + "/.well-known/openid-configuration"))
+func get_openid_config(endpoint string) error {
+ resp, err := http.Get(endpoint + "/.well-known/openid-configuration")
+ if err != nil {
+ return err
+ }
defer resp.Body.Close()
+
if resp.StatusCode != 200 {
- log.Fatal(fmt.Sprintf(
- "Got response code %d from openid-configuration\n",
- resp.StatusCode,
- ))
+ return errors.New("Got non-200 response code from openid-configuration")
}
- e(json.NewDecoder(resp.Body).Decode(&openid_configuration))
- resp = er(http.Get(openid_configuration.JwksUri))
+ if err := json.NewDecoder(resp.Body).Decode(&openid_configuration); err != nil {
+ return err
+ }
+
+ resp, err = http.Get(openid_configuration.JwksUri)
+ if err != nil {
+ return err
+ }
defer resp.Body.Close()
+
if resp.StatusCode != 200 {
- log.Fatal(fmt.Sprintf(
- "Got response code %d from JwksUri\n",
- resp.StatusCode,
- ))
+ return errors.New("Got non-200 response code from JwksUri")
}
if config.Openid.Authorize != "" {
@@ -84,7 +88,10 @@ func get_openid_config(endpoint string) {
config.Openid.Authorize
}
- jwks_json := er(io.ReadAll(resp.Body))
+ jwks_json, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return err
+ }
/*
* TODO: The key set is never updated, which is technically incorrect.
@@ -92,7 +99,12 @@ func get_openid_config(endpoint string) {
* controlling when to do it manually. Remember to wrap it around a
* mutex or some semaphores though.
*/
- openid_keyfunc = er(keyfunc.NewJWKSetJSON(jwks_json))
+ openid_keyfunc, err = keyfunc.NewJWKSetJSON(jwks_json)
+ if err != nil {
+ return err
+ }
+
+ return nil
}
func generate_authorization_url() string {