aboutsummaryrefslogtreecommitdiff
path: root/docs/Authentication.md
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-03-28 19:16:15 +0300
committertranstrike <transtrike@gmail.com>2021-03-28 19:16:15 +0300
commita789a23c3c8ddde8188f2da40402a1803f838f89 (patch)
treedaff292b6562a7f49cc2900e249a77243b8919e9 /docs/Authentication.md
parent4f6d554f95afac9c4eb7358596e4a7ce3aeb5a30 (diff)
parent15904cb3d2ef9442b682322353c378ab321520e5 (diff)
downloadDevHive-a789a23c3c8ddde8188f2da40402a1803f838f89.tar
DevHive-a789a23c3c8ddde8188f2da40402a1803f838f89.tar.gz
DevHive-a789a23c3c8ddde8188f2da40402a1803f838f89.zip
Dev changes merged into ProfilePicLayer branch
Diffstat (limited to 'docs/Authentication.md')
-rw-r--r--docs/Authentication.md52
1 files changed, 52 insertions, 0 deletions
diff --git a/docs/Authentication.md b/docs/Authentication.md
new file mode 100644
index 0000000..f9e6525
--- /dev/null
+++ b/docs/Authentication.md
@@ -0,0 +1,52 @@
+Certain actions with the API require User authentication. In DevHive, all authentication is done with [JSON Web Tokens](https://en.wikipedia.org/wiki/JSON_Web_Token).
+
+The JWTs must be sent as a [Bearer Token](https://www.oauth.com/oauth2-servers/differences-between-oauth-1-2/bearer-tokens/).
+
+## Structure of tokens
+
+The main contents of a User's token are the `UserName`, `ID` and `Roles`.
+
+Sample token:
+```
+eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJJRCI6IjI3ZTIwM2JkLTUzMTItNDgzMS05MzM0LWNkM2MyMGU1ZDY3MiIsIlVzZXJuYW1lIjoidGVzdCIsInJvbGUiOiJVc2VyIiwibmJmIjoxNjEyMzYxOTc1LCJleHAiOjE2MTI5MDgwMDAsImlhdCI6MTYxMjM2MTk3NX0.ZxhDSUsDf9cGig03QpzNgj3dkqbcfAoFXVIfixYGurzhd0l1_IO79UpE_Sb6ZU9hz3IT1XPrlrQ_Kd46L7xcQg
+```
+[Decoded](https://jwt.io/):
+
+- Header
+```json
+{
+ "alg": "HS512",
+ "typ": "JWT"
+}
+```
+
+- Data
+```json
+{
+ "ID": "27e203bd-5312-4831-9334-cd3c20e5d672",
+ "Username": "test",
+ "role": "User",
+ "nbf": 1612361975,
+ "exp": 1612908000,
+ "iat": 1612361975
+}
+```
+
+- Signature
+```
+HMACSHA512(
+ base64UrlEncode(header) + "." +
+ base64UrlEncode(payload)
+)
+```
+
+## Token validation
+
+All token validations are done in the User Service. Depending on the situation, we can differentiate a couple types of authentication:
+
+|||
+|---|---|
+|1|Has the role "User" or "Admin"|
+|2|Has the role "User" and is the owner/author of the object or has the role "Admin"|
+|3|Has the role "Admin"|
+||| \ No newline at end of file