Skip to content

Commit 37b25a2

Browse files
authored
Update 11-authentication.livemd
1 parent 4d60609 commit 37b25a2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

modules/11-authentication.livemd

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Authentication mechanism can be simple or complex. Security industry best pract
6363

6464
Tokens are ... long strings of random characters used to identify an entity, session, as a badge for access. Used for authentication, used for session management, provided by authorization servers.
6565

66+
Generate token, assign token to user, check token validity, expire token.
67+
6668

6769
Common implementations include OAuth:
6870

@@ -78,6 +80,58 @@ Base64 encoded and cryptographically signed
7880

7981
Tokens, like other authentication credentials, etc. must be protected in transit and at rest.
8082

83+
Why use JWT? For post authentication authorization Can be signed and encrypted -> trust; low overhead; Integrity of information being transmited and non-repudiation; JWT checkers validate token; token belongs to user
84+
85+
Expiration /Refresh
86+
87+
Why use OAuth? when Users need access to third party services, outside of your environment where you don't want to share your credentials with those third parties. In OAuth protocol/architecture, an authorization service brokers access and grants users an access token to present, in place of credentials.
88+
89+
90+
### <span style="color:blue;">Example</span> / <span style="color:red;">Quiz</span>
91+
92+
Create/Generate Token
93+
```
94+
95+
96+
```
97+
98+
99+
100+
101+
Validate Token
102+
```
103+
def connect(%{"authorize" => token}, socket, _connect_info) do //
104+
case JwtChecker.validate_token(token)do
105+
...
106+
...
107+
```
108+
109+
https://dev.to/onpointvn/implement-jwt-authentication-with-phoenix-token-n58
110+
(https://hexdocs.pm/guardian/Guardian.Token.Jwt.html)
111+
112+
https://elixirschool.com/blog/jwt-auth-with-joken/
113+
114+
115+
116+
### <span style="color:blue;">Example</span> / <span style="color:red;">Quiz</span>
117+
118+
Oauth simple
119+
120+
User Authenticated into Application/Service X
121+
Application/Service X prompts user if they want to login using social media account credentials
122+
User Logs into social media account/other service
123+
Authorization Server/Service Generates Access Token
124+
Service X sends Token for limited access to Social Media Account (instead of sharing credentials)
125+
126+
https://www.youtube.com/watch?v=996OiexHze0
127+
128+
If you're familiar with Kerberos, somewhat similar - three primary entities, requesting, service one, service 2, intermediary server that handles issuing tokens that get presented in lieu of credentials
129+
130+
```
131+
[OAuth2.Client module ](https://hexdocs.pm/oauth2/OAuth2.Client.html)
132+
133+
134+
81135
## Sessions
82136
83137
### Description

0 commit comments

Comments
 (0)