summaryrefslogtreecommitdiff
path: root/internal/util
diff options
context:
space:
mode:
Diffstat (limited to 'internal/util')
-rw-r--r--internal/util/util.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/util/util.go b/internal/util/util.go
index 8dee61e..30767c3 100644
--- a/internal/util/util.go
+++ b/internal/util/util.go
@@ -4,8 +4,11 @@ import (
"crypto/rand"
"fmt"
"os"
+ "strings"
"time"
+ "net/url"
+
"github.com/jwijenbergh/eduvpn-common/internal/types"
)
@@ -31,3 +34,23 @@ func EnsureDirectory(directory string) error {
}
return nil
}
+
+// See https://github.com/eduvpn/documentation/blob/dc4d53c47dd7a69e95d6650eec408e16eaa814a2/SERVER_DISCOVERY_SKIP_WAYF.md
+// URL encode for skipping where are you from (WAYF). Note that this right now is basically an alias to QueryEscape
+func WAYFEncode(input string) string {
+ // QueryReplace already replaces a space with a +
+ // see https://go.dev/play/p/pOfrn-Wsq5
+ return url.QueryEscape(input)
+}
+
+// See https://github.com/eduvpn/documentation/blob/dc4d53c47dd7a69e95d6650eec408e16eaa814a2/SERVER_DISCOVERY_SKIP_WAYF.md
+func ReplaceWAYF(authTemplate string, authURL string, orgID string) string {
+ if authTemplate == "" {
+ return authURL
+ }
+ // Replace authURL
+ authTemplate = strings.Replace(authTemplate, "@RETURN_TO@", WAYFEncode(authURL), 1)
+ // Replace ORG ID
+ authTemplate = strings.Replace(authTemplate, "@ORG_ID@", WAYFEncode(orgID), 1)
+ return authTemplate
+}