diff --git a/.github/workflows/markdown.yml b/.github/workflows/markdown.yml
new file mode 100644
index 0000000..ad67936
--- /dev/null
+++ b/.github/workflows/markdown.yml
@@ -0,0 +1,12 @@
+name: none-shall-pass
+
+on:
+ workflow_dispatch:
+ push:
+
+jobs:
+ none-shall-pass:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: thevickypedia/none-shall-pass@v3
diff --git a/README.md b/README.md
index 76d730b..7fe8421 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
[![Pypi-format](https://img.shields.io/pypi/format/stream-localhost)](https://pypi.org/project/stream-localhost/#files)
[![Pypi-status](https://img.shields.io/pypi/status/stream-localhost)][pypi]
-# Video Streaming
+# PyStream
Python module to, stream videos via authenticated sessions using FastAPI
## Install
@@ -23,9 +23,8 @@ import pystream
if __name__ == '__main__':
kwargs = dict(
- username="foo",
- password="bar",
- video_source=os.path.join(os.path.expanduser('~'), 'Downloads'),
+ authorization=[{"Alan Turing": "Pr0gRamM1ng"}, {"Linus Torvalds": "LinuxOS"}],
+ video_source=os.path.join(os.path.expanduser('~'), 'Downloads')
)
# Add the following to host on local IP address, skip for localhost (127.0.0.1)
# kwargs["video_host"] = pystream.utils.get_local_ip()
@@ -37,8 +36,7 @@ if __name__ == '__main__':
> To use custom filenames, set the env var `env_file` as `key` and the _filename_ as its `value`
**Mandatory**
-- **USERNAME**: Any username of choice.
-- **PASSWORD**: Any password of choice.
+- **AUTHORIZATION**: List of dictionaries with `username` as key and `password` as value.
- **VIDEO_SOURCE**: Source path for video files.
> :bulb: Files starting with `_` _(underscore)_ and `.` _(dot)_ will be ignored
diff --git a/authentication.md b/authentication.md
new file mode 100644
index 0000000..da6039b
--- /dev/null
+++ b/authentication.md
@@ -0,0 +1,32 @@
+## Authentication
+`PyStream` uses two ways of authentication, the `username` and `password` to gain access to the server and
+a `session_token` generated by the server to access directories and streaming content.
+
+### Username and Password
+
+#### Frontend
+- UI creates hex values for username and password using native JS
+- These hex values are then used the calculate the hash
+- Calculated hash is then base64 encoded using native JS, before sending the signature to the API in an authorization header
+
+#### Backend
+- API decodes the base64 encoded ascii string, then decodes the HEX received in authorization header
+- Then the value is broken down to, username, signature and timestamp
+- The decoded username is used to get the stored password from env variables, which are then hex encoded
+- API creates a hash signature using the hex username, hex password, and the timestamp
+- These signatures are then compared for authentication purpose
+
+### Session Token
+
+- Once the login has been successful, the API creates a randomly generated 64 bit url safe token
+- This token is stored as unique key for each user
+- The API then forms a payload with the username, key, and the timestamp
+- This payload is then encrypted using Cryptography's Fernet, which can be retrieved only using the key
+- This encrypted payload is stored as a cookie before sending a `JSONResponse` with a `redirect_url`
+> Since the UI uses `AJAX` for authentication POST call, a `RedirectResponse` from FastAPI will not work,
+> as the call will simply follow the redirect to `GET` the content instead of redirecting the page.
+- The `redirect_url` from the JSON response is fetched, to alter `location.href`
+> This form of redirect will transfer cookies to the new page but not the headers,
+> so the username and password are lost in the frontend at this point
+- From then on, all calls to the backend including redirects, directory navigation and, streaming will carry the cookie
+- The `session_token` is the only form of authentication from this point onward
diff --git a/doc_gen/index.rst b/doc_gen/index.rst
index bd40dfe..7394aef 100644
--- a/doc_gen/index.rst
+++ b/doc_gen/index.rst
@@ -11,6 +11,7 @@ Stream-Localhost - A secured interface to stream videos
:caption: Read Me:
README
+ authentication
Main Module
===========
diff --git a/docs/README.html b/docs/README.html
index 166228f..f55bc11 100644
--- a/docs/README.html
+++ b/docs/README.html
@@ -6,7 +6,7 @@
-