diff --git a/README.md b/README.md
index ae5dbe6..ec00ecc 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,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
@@ -24,9 +24,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()
@@ -38,9 +37,7 @@ if __name__ == '__main__':
> Refer the [wiki page][wiki] for more information.
**Mandatory**
-- **USERNAME**: Any username of choice.
-- **PASSWORD**: Any password of choice.
-- **SECRET**: Any private key to encode and decode JWT.
+- **AUTHORIZATION**: Dictionary of key-value pairs 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..dd7810e
--- /dev/null
+++ b/authentication.md
@@ -0,0 +1,39 @@
+## 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
+> [Signature Authentication][signature-authentication]
+#### 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
+> [Symmetric Encryption][symmetric-encryption]
+- 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
+
+### References
+- [symmetric-encryption]
+- [signature-authentication]
+
+[symmetric-encryption]: https://cryptography.io/en/latest/fernet/
+[signature-authentication]: https://developers.expediagroup.com/docs/products/rapid/resources/reference/signature-authentication
diff --git a/doc_gen/index.rst b/doc_gen/index.rst
index ff8317e..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
===========
@@ -42,6 +43,13 @@ Images
:members:
:undoc-members:
+Secure
+======
+
+.. automodule:: pystream.models.secure
+ :members:
+ :undoc-members:
+
Squire
======
diff --git a/docs/README.html b/docs/README.html
index d775c51..57f3bdf 100644
--- a/docs/README.html
+++ b/docs/README.html
@@ -6,7 +6,7 @@
-
:bulb: Environment variables can (optionally) be loaded from any file.
-Refer the wiki page for more information.
+
:bulb: Environment variables can be loaded from any file. Filename defaults to .env
+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.
-
SECRET: Any private key to encode and decode JWT.
+
AUTHORIZATION: Dictionary of key-value pairs with username as key and password as value.