|
| 1 | ++++ |
| 2 | +title = "Tech Share: Open ID connect" |
| 3 | +author = ["Chop Tr (chop.dev)"] |
| 4 | +summary = "Introduction about OAuth 2.0 and OpenID Connect" |
| 5 | +date = 2025-07-06T00:00:00+07:00 |
| 6 | +tags = ["oidc", "open-id-connect", "authentication", "tech-share"] |
| 7 | +draft = false |
| 8 | ++++ |
| 9 | + |
| 10 | +Tech Share: Open ID connect |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +#### Authentication |
| 17 | + |
| 18 | + <!-- .element: style="margin: auto" --> |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +#### Authentication |
| 23 | + |
| 24 | + <!-- .element: style="margin: auto" --> |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +#### Authentication |
| 29 | + |
| 30 | +- Why you think we need third-party Authentication? <!-- .element: class="fragment" --> |
| 31 | +- Why do we need a method that the resource provider can authenticate the user without rely on the Authentication Provider? <!-- .element: class="fragment" --> |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +#### Understanding OAuth 2.0 |
| 36 | + |
| 37 | +- OAuth Flow |
| 38 | +- Demo with real word scenario |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +#### OAuth Flow |
| 43 | + |
| 44 | +1. **Authorization Request** |
| 45 | + |
| 46 | + The process begins when a user tries to access a resource or service that requires authentication. |
| 47 | + |
| 48 | +2. **User Authentication** |
| 49 | + |
| 50 | + The authorization server then prompts the user to authenticate themselves. |
| 51 | + |
| 52 | +3. **Authorization Grant** |
| 53 | + |
| 54 | + Once the user is authenticated, the authorization server asks the user to grant or deny permission for the requested access. |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +#### OAuth Flow |
| 59 | + |
| 60 | +4. **Access Token Request** |
| 61 | + |
| 62 | + The client then sends a request to the |
| 63 | + authorization server to exchange the authorization code for an access token. |
| 64 | + |
| 65 | +5. **Access Token Response** |
| 66 | + |
| 67 | + If the authorization server validates the |
| 68 | + request, it issues an access token to the client. |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +#### OAuth Flow |
| 73 | + |
| 74 | +6. **Access Resource**: |
| 75 | + |
| 76 | + The client uses the access token to request resources |
| 77 | + from the resource server. |
| 78 | + |
| 79 | +7. **Refresh Token (Optional)** |
| 80 | + |
| 81 | + In some cases, the authorization server may |
| 82 | + also issue a refresh token alongside the access token. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +#### OAuth Flow |
| 87 | + |
| 88 | +1. **Backchannel Flow**: Also known as the Authorization Code Flow, this is |
| 89 | + used for server-side applications where an authorization code is first |
| 90 | + returned and then exchanged for an access token. |
| 91 | +2. **Implicit Flow**: This is typically used for client-side applications where |
| 92 | + the access token is returned directly to the client without an intermediate |
| 93 | + authorization code. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +#### Demo OAuth flow |
| 98 | + |
| 99 | +[Miro](https://miro.com/app/board/uXjVIgkehRc=/) |
| 100 | + |
| 101 | +[Diagram](https://chop.dev/posts/tech-share--open-id-connect/) |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +#### OpenID Connect |
| 106 | + |
| 107 | +> A fun fact about OAuth 2.0 is that it was not designed with <span style="color: lightgreen">Authentication</span> focus. |
| 108 | +> It mainly about <span style="color: orange">delegated Authorization</span>. |
| 109 | +
|
| 110 | +--- |
| 111 | + |
| 112 | +#### OpenID Connect |
| 113 | + |
| 114 | +1. **Identity Tokens** |
| 115 | + |
| 116 | + OpenID Connect introduces the concept of an ID token, |
| 117 | + which contains information about the user, such as their unique identifier, |
| 118 | + name, and email address. This token is encoded as a JSON Web Token (JWT). |
| 119 | + |
| 120 | +2. **UserInfo Endpoint** |
| 121 | + |
| 122 | + OpenID Connect provides a UserInfo endpoint that |
| 123 | + allows clients to retrieve additional information about the user, such as |
| 124 | + profile details, after they have authenticated. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +#### OpenID Connect |
| 129 | + |
| 130 | +3. **Standardized Scopes** |
| 131 | + |
| 132 | + OpenID Connect defines standard scopes like |
| 133 | + `openid`, `profile`, `email`, etc., which specify the level of access and |
| 134 | + information the client is requesting. |
| 135 | + |
| 136 | +4. **Discovery and Dynamic Registration** |
| 137 | + |
| 138 | + OpenID Connect supports discovery, |
| 139 | + allowing clients to dynamically discover information about the OpenID |
| 140 | + Provider (OP), such as its endpoints and supported features. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +#### OpenID Connect |
| 145 | + |
| 146 | +5. **Session Management** |
| 147 | + |
| 148 | + OpenID Connect provides mechanisms for managing user |
| 149 | + sessions, allowing clients to detect when a user logs out or when their |
| 150 | + session expires. |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +#### JSON Web Token (JWT) |
| 155 | + |
| 156 | +1. **Header**: |
| 157 | + |
| 158 | + The header typically consists of two parts: the type of the |
| 159 | + token, which is JWT, and the signing algorithm being used, such as HMAC |
| 160 | + SHA256 or RSA. |
| 161 | + |
| 162 | + Example: |
| 163 | + |
| 164 | + json { "alg": "HS256", "typ": "JWT" } |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +#### JSON Web Token (JWT) |
| 169 | + |
| 170 | +2. **Payload**: |
| 171 | + |
| 172 | + The payload contains the claims. Claims are statements about an |
| 173 | + entity (typically, the user) and additional data. There are three types of |
| 174 | + claims: registered, public, and private claims. |
| 175 | + |
| 176 | + Example: |
| 177 | + |
| 178 | + json { "sub": "1234567890", "name": "John Doe", "admin": true } |
| 179 | + |
| 180 | +--- |
| 181 | + |
| 182 | +#### JSON Web Token (JWT) |
| 183 | + |
| 184 | +3. **Signature**: |
| 185 | + |
| 186 | + To create the signature part, you have to take the encoded |
| 187 | + header, the encoded payload, a secret, the algorithm specified in the |
| 188 | + header, and sign that. |
| 189 | + |
| 190 | + Example: |
| 191 | + |
| 192 | + HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret) |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +#### Conclusion |
| 197 | + |
| 198 | +> Why do you think we need third-party authentication? |
| 199 | +
|
| 200 | +- **Separation of Concerns** |
| 201 | + |
| 202 | +- **Ease of Implementation** |
| 203 | + |
| 204 | +- **Standardization** |
| 205 | + |
| 206 | +--- |
| 207 | + |
| 208 | +#### Conclusion |
| 209 | + |
| 210 | +> Why do we need a method that the resource provider can authenticate the user |
| 211 | +> without rely on the Authentication Provider? |
| 212 | +
|
| 213 | +- **Reduced Load on Authentication Servers** |
| 214 | + |
| 215 | +- **Improved Performance** |
| 216 | + |
| 217 | +- **Resilience and Availability** |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +#### Reference resource |
| 222 | + |
| 223 | +[crate:firebase-auth](https://crates.io/crates/firebase-auth) |
| 224 | + |
| 225 | +[github:firebase-auth](https://github.com/trchopan/firebase-auth) |
| 226 | + |
| 227 | + <!-- .element: style="margin: auto" width="450" --> |
0 commit comments