diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-05 13:17:24 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-07-05 13:17:24 +0200 |
| commit | 1865b016d0cca74cd3703db5a3b4217917988dec (patch) | |
| tree | 3da84dbc4f1ad49221c25fb83f402d27deb34138 /internal/util | |
| parent | e39b9a8a405fa8e5f73c32bb03a3f349f7f9f92d (diff) | |
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)
Diffstat (limited to 'internal/util')
| -rw-r--r-- | internal/util/util.go | 23 |
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 +} |
