summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.go23
-rw-r--r--client/redirect.go23
2 files changed, 25 insertions, 21 deletions
diff --git a/client/client.go b/client/client.go
index 2afb1a9..00ed49e 100644
--- a/client/client.go
+++ b/client/client.go
@@ -112,22 +112,6 @@ type Client struct {
mu sync.Mutex
}
-func (c *Client) NeedsMobileRedirect() bool {
- splitted := strings.Split(c.Name, ".")
- last := splitted[len(splitted)-1]
- return last == "android" || last == "ios"
-}
-
-func (c *Client) MobileRedirect() string {
- vals := map[string]string{
- "org.letsconnect-vpn.app.ios": "org.letsconnect-vpn.app.ios:/api/callback",
- "org.letsconnect-vpn.app.android": "org.letsconnect-vpn.app:/api/callback",
- "org.eduvpn.app.ios": "org.eduvpn.app.ios:/api/callback",
- "org.eduvpn.app.android": "org.eduvpn.app:/api/callback",
- }
- return vals[c.Name]
-}
-
func (c *Client) updateTokens(srv server.Server) error {
if c.TokenGetter == nil {
return errors.New("no token getter defined")
@@ -377,16 +361,13 @@ func (c *Client) locationCallback(ck *cookie.Cookie) error {
func (c *Client) loginCallback(ck *cookie.Cookie, srv server.Server) error {
// get a custom redirect
- cr := ""
- if c.NeedsMobileRedirect() {
- cr = c.MobileRedirect()
- }
+ cr := CustomRedirect(c.Name)
url, err := server.OAuthURL(srv, c.Name, cr)
if err != nil {
return err
}
authCodeURI := ""
- if c.NeedsMobileRedirect() {
+ if cr != "" {
errChan := make(chan error)
go func() {
err := c.FSM.GoTransitionRequired(StateOAuthStarted, &srvtypes.RequiredAskTransition{
diff --git a/client/redirect.go b/client/redirect.go
new file mode 100644
index 0000000..1a06ed6
--- /dev/null
+++ b/client/redirect.go
@@ -0,0 +1,23 @@
+package client
+
+// customRedirects supplies redirect values that should be handled by the app itself
+// here we hardcode the redirect values that we should use in the OAuth requests
+// these values were taken from https://git.sr.ht/~fkooman/vpn-user-portal/tree/v3/item/src/OAuth/VpnClientDb.php
+var customRedirects = map[string]string{
+ "org.letsconnect-vpn.app.ios": "org.letsconnect-vpn.app.ios:/api/callback",
+ "org.letsconnect-vpn.app.android": "org.letsconnect-vpn.app:/api/callback",
+ "org.eduvpn.app.ios": "org.eduvpn.app.ios:/api/callback",
+ "org.eduvpn.app.android": "org.eduvpn.app:/api/callback",
+}
+
+// CustomRedirect returns the custom redirect string for a clientID `cid`
+// Empty string if none is defined or one is defined but is empty.
+// In both empty string cases, eduvpn-common handles the redirects as 127.0.0.1 local server redirects
+// If a non-empty string is returned, the redirect should be handled by the client and we only use the redirect URI value in our OAuth requests
+func CustomRedirect(cid string) string {
+ v, ok := customRedirects[cid]
+ if !ok {
+ return ""
+ }
+ return v
+}