summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Auth.js9
-rw-r--r--src/Auth.purs10
-rw-r--r--src/Main.purs13
3 files changed, 25 insertions, 7 deletions
diff --git a/src/Auth.js b/src/Auth.js
index 3c077ce..998dc1a 100644
--- a/src/Auth.js
+++ b/src/Auth.js
@@ -49,7 +49,14 @@ export const _clearSessionCookie = () => {
document.cookie = "authelia_session=; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=None; Secure";
};
-export const _getRedirect = (Just) => (Nothing) => (x) => () => {
+export const _getQueryRedirect = (Just) => (Nothing) => () => {
+ const ps = new URLSearchParams(window.location.search);
+ const p = ps?.get("rd");
+ if (p) return Just(p);
+ return Nothing;
+};
+
+export const _getResponseRedirect = (Just) => (Nothing) => (x) => () => {
const data = x["data"];
if (!data) return Nothing;
const r = x["data"]["redirect"];
diff --git a/src/Auth.purs b/src/Auth.purs
index 1b5cd16..40a919e 100644
--- a/src/Auth.purs
+++ b/src/Auth.purs
@@ -33,6 +33,10 @@ foreign import _clearSessionCookie :: Effect Unit
clearSessionCookie :: forall m. MonadEffect m => m Unit
clearSessionCookie = liftEffect _clearSessionCookie
-foreign import _getRedirect :: forall a. (a -> Maybe a) -> Maybe a -> Foreign -> Effect (Maybe String)
-getRedirect :: forall m . MonadEffect m => Foreign -> m (Maybe String)
-getRedirect x = liftEffect $ _getRedirect Just Nothing x
+foreign import _getQueryRedirect :: forall a. (a -> Maybe a) -> Maybe a -> Effect (Maybe String)
+getQueryRedirect :: forall m . MonadEffect m => m (Maybe String)
+getQueryRedirect = liftEffect $ _getQueryRedirect Just Nothing
+
+foreign import _getResponseRedirect :: forall a. (a -> Maybe a) -> Maybe a -> Foreign -> Effect (Maybe String)
+getResponseRedirect :: forall m . MonadEffect m => Foreign -> m (Maybe String)
+getResponseRedirect x = liftEffect $ _getResponseRedirect Just Nothing x
diff --git a/src/Main.purs b/src/Main.purs
index 983a805..c4b4fa5 100644
--- a/src/Main.purs
+++ b/src/Main.purs
@@ -3,7 +3,7 @@ module Main where
import Prelude
import Audio as Audio
-import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, clearSessionCookie, getRedirect)
+import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, clearSessionCookie, getQueryRedirect, getResponseRedirect)
import Config as Config
import Data.String as String
import Data.Array (head)
@@ -248,13 +248,20 @@ mainAuth = launchAff_ do
passwordInp <- byId "lcolonq-auth-password"
username <- getValue usernameInp
password <- getValue passwordInp
+ rd <- getQueryRedirect
{ json: resp } <- fetch "/api/firstfactor"
{ method: POST
, headers: { "Content-Type": "application/json" }
- , body: UI.toJSON { username, password }
+ , body: UI.toJSON
+ { username
+ , password
+ , targetURL: case rd of
+ Just r -> r
+ Nothing -> "https://secure.colonq.computer"
+ }
}
res <- resp
- getRedirect res >>= case _ of
+ getResponseRedirect res >>= case _ of
Nothing -> do
err <- byId "lcolonq-auth-error"
removeClass "lcolonq-invisible" err