summaryrefslogtreecommitdiff
path: root/internal/server/endpoints/endpoints.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-04-12 22:52:49 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2023-09-25 09:43:37 +0200
commita23c3e61c5d89ef67973891b5b3a176c06e1b174 (patch)
treef1eed03b047f8affd3d5123fa5c9e868ac7d8bec /internal/server/endpoints/endpoints.go
parentee95eb45708e1fa766a63866d26d05d13f23e8c9 (diff)
Refactor: Split internal server into multiple packages
- Pass contexts - Have separate packages for e.g. custom, institute and secure - internet servers, profiles.... - Return types from the public ./types package with a Public() method
Diffstat (limited to 'internal/server/endpoints/endpoints.go')
-rw-r--r--internal/server/endpoints/endpoints.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/server/endpoints/endpoints.go b/internal/server/endpoints/endpoints.go
new file mode 100644
index 0000000..75bca55
--- /dev/null
+++ b/internal/server/endpoints/endpoints.go
@@ -0,0 +1,53 @@
+package endpoints
+
+import (
+ "net/url"
+
+ "github.com/go-errors/errors"
+)
+
+type List struct {
+ API string `json:"api_endpoint"`
+ Authorization string `json:"authorization_endpoint"`
+ Token string `json:"token_endpoint"`
+}
+
+type Versions struct {
+ V2 List `json:"http://eduvpn.org/api#2"`
+ V3 List `json:"http://eduvpn.org/api#3"`
+}
+
+// Endpoints defines the json format for /.well-known/vpn-user-portal".
+type Endpoints struct {
+ API Versions `json:"api"`
+ V string `json:"v"`
+}
+
+func (e Endpoints) Validate() error {
+ v3 := e.API.V3
+ pAPI, err := url.Parse(v3.API)
+ if err != nil {
+ return errors.WrapPrefix(err, "failed to parse API endpoint", 0)
+ }
+ pAuth, err := url.Parse(v3.Authorization)
+ if err != nil {
+ return errors.WrapPrefix(err, "failed to parse API authorization endpoint", 0)
+ }
+ pToken, err := url.Parse(v3.Token)
+ if err != nil {
+ return errors.WrapPrefix(err, "failed to parse API token endpoint", 0)
+ }
+ if pAPI.Scheme != pAuth.Scheme {
+ return errors.Errorf("API scheme: '%v', is not equal to authorization scheme: '%v'", pAPI.Scheme, pAuth.Scheme)
+ }
+ if pAPI.Scheme != pToken.Scheme {
+ return errors.Errorf("API scheme: '%v', is not equal to token scheme: '%v'", pAPI.Scheme, pToken.Scheme)
+ }
+ if pAPI.Host != pAuth.Host {
+ return errors.Errorf("API host: '%v', is not equal to authorization host: '%v'", pAPI.Host, pAuth.Host)
+ }
+ if pAPI.Host != pToken.Host {
+ return errors.Errorf("API host: '%v', is not equal to token host: '%v'", pAPI.Host, pToken.Host)
+ }
+ return nil
+}