summaryrefslogtreecommitdiff
path: root/src/Auth.purs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-11-05 02:58:33 -0500
committerLLLL Colonq <llll@colonq>2024-11-05 02:58:33 -0500
commitcf0070ac5a78d8042fa74d407fb9cb65352e2066 (patch)
tree85fb5cee6c7533b7ae6de846ed447772d7b67296 /src/Auth.purs
Initial commit
Diffstat (limited to 'src/Auth.purs')
-rw-r--r--src/Auth.purs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Auth.purs b/src/Auth.purs
new file mode 100644
index 0000000..2a53629
--- /dev/null
+++ b/src/Auth.purs
@@ -0,0 +1,29 @@
+module Auth where
+
+import Prelude
+
+import Config (authRedirectURL, clientID)
+import Data.Array (fold)
+import Data.Maybe (Maybe(..))
+import Data.Tuple (Tuple(..))
+import Effect (Effect)
+import Effect.Class (class MonadEffect, liftEffect)
+
+foreign import _startTwitchAuth :: String -> String -> Effect Unit
+startTwitchAuth :: forall m. MonadEffect m => m Unit
+startTwitchAuth = liftEffect $ _startTwitchAuth clientID authRedirectURL
+
+type AuthInfo = Tuple String String
+foreign import _getToken :: forall a. (a -> Maybe a) -> Maybe a -> (a -> a -> Tuple a a) -> Effect (Maybe (Tuple String String))
+getToken :: forall m. MonadEffect m => m (Maybe AuthInfo)
+getToken = liftEffect $ _getToken Just Nothing Tuple
+
+authHeader :: AuthInfo -> String
+authHeader (Tuple t n) =
+ fold
+ [ "FIG-TWITCH token=\""
+ , t
+ , "\", nonce=\""
+ , n
+ , "\""
+ ]