From 1865b016d0cca74cd3703db5a3b4217917988dec Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 5 Jul 2022 13:17:24 +0200 Subject: Refactor: Handling of different servers and identifiers - Uses OrgID for Secure Internet and gets the data from discovery - Uses URL for Institute/Custom and gets the data from discovery - Implements SKIP WAYF as we now have the needed data - Implements an initial change location with a default location (NL right now) --- internal/util/util.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'internal/util') 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 +} -- cgit v1.2.3