\section{OAuth 2.0} \begin{frame}[shrink=15]{Mi az OAuth 2.0?} \begin{block}{Definíció} Autorizációs protokoll - korlátozott hozzáférés jelszó megosztása nélkül. \end{block} \begin{itemize} \item RFC 6749 (2012) \item Google, Facebook, GitHub használja \item Példa: App hozzáfér Google Drive-hoz jelszó nélkül \end{itemize} \end{frame} \begin{frame}[shrink=15]{OAuth 2.0 szerepkörök} \begin{enumerate} \item \textbf{Resource Owner}: Felhasználó (birtokolja erőforrást) \item \textbf{Client}: Alkalmazás (hozzáférést kér) \item \textbf{Authorization Server}: Token kiállító \item \textbf{Resource Server}: Védett erőforrás tároló \end{enumerate} \end{frame} \begin{frame}[shrink=15]{OAuth 2.0 Flow} \begin{center} \begin{tikzpicture}[node distance=1.8cm, auto] \node (ro) [rectangle, draw, text width=1.8cm, text centered] {Resource Owner}; \node (client) [rectangle, draw, below of=ro, text width=1.8cm, text centered] {Client}; \node (auth) [rectangle, draw, right of=client, xshift=2.5cm, text width=2cm, text centered] {Auth Server}; \node (res) [rectangle, draw, below of=auth, text width=2cm, text centered] {Resource Server}; \draw[->, thick] (client) -- node[left] {1. Kérés} (ro); \draw[->, thick] (ro) -- node[above] {2. OK} (auth); \draw[->, thick] (auth) -- node[right] {3. Token} (client); \draw[->, thick] (client) -- node[above] {4. API} (res); \draw[->, thick] (res) -- node[below] {5. Data} (client); \end{tikzpicture} \end{center} \end{frame} \begin{frame}[shrink=15]{Grant Types} \begin{enumerate} \item \textbf{Authorization Code}: Szerver app, legbiztonságosabb \item \textbf{Implicit}: \textcolor{red}{Elavult!} \item \textbf{Resource Owner Password}: Közvetlen jelszó, megbízható app \item \textbf{Client Credentials}: Machine-to-machine \item \textbf{PKCE}: Modern mobil/SPA \end{enumerate} \end{frame} \begin{frame}[shrink=20]{Authorization Code Flow lépések} \begin{enumerate} \item Kliens átirányít: \texttt{/authorize?client\_id=\&redirect\_uri=\&scope=} \item Felhasználó bejelentkezik és hozzájárul \item Auth Server visszairányít: \texttt{redirect\_uri?code=AUTH\_CODE} \item Kliens kicseréli code-ot: POST \texttt{/token} \item Auth Server ad access token-t (+ refresh) \item Kliens használja tokent: \texttt{Authorization: Bearer } \end{enumerate} \end{frame} \begin{frame}[fragile,shrink=20]{Authorization Code - Auth kérés} \begin{verbatim} GET /oauth/authorize? response_type=code& client_id=YOUR_CLIENT_ID& redirect_uri=https://app.com/callback& scope=read write& state=xyz123 \end{verbatim} \begin{verbatim} // Callback GET https://app.com/callback? code=AUTH_CODE& state=xyz123 \end{verbatim} \end{frame} \begin{frame}[fragile,shrink=20]{Authorization Code - Token csere} \begin{verbatim} POST /oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code& code=AUTH_CODE& redirect_uri=https://app.com/callback& client_id=YOUR_ID& client_secret=YOUR_SECRET \end{verbatim} \begin{verbatim} // Válasz { "access_token": "eyJ...", "expires_in": 3600, "refresh_token": "tGzv..." } \end{verbatim} \end{frame} \begin{frame}[shrink=15]{PKCE (Proof Key for Code Exchange)} \begin{block}{Miért?} Authorization Code Flow biztonságosabbá tétele mobil/SPA app-okhoz. \end{block} \begin{enumerate} \item Kliens generál \texttt{code\_verifier} (random string) \item Hash: \texttt{code\_challenge = SHA256(code\_verifier)} \item Auth kéréshez csatol: \texttt{code\_challenge} \item Token kérésnél küldi: \texttt{code\_verifier} \item Server validálja: \texttt{SHA256(verifier) == challenge} \end{enumerate} \begin{alertblock}{Védelem} Megakadályozza authorization code ellopását. \end{alertblock} \end{frame} \begin{frame}[shrink=15]{Scope és Permission} \begin{block}{Scope} Jogosultság amit app kér. Példa: \texttt{read:user write:repo} \end{block} \begin{itemize} \item Felhasználó látja mit kér az app \item Csak kért scope-okat kapja meg \item Token tartalmazza scope-okat \end{itemize} \begin{exampleblock}{GitHub példa} \texttt{repo, user, gist, notifications} \end{exampleblock} \end{frame} \begin{frame}[fragile,shrink=20]{Access Token használata} \begin{verbatim} // API kérés Bearer token-nel GET /api/user/profile Authorization: Bearer eyJhbGciOiJIUzI1NiIs... \end{verbatim} \begin{verbatim} // Express validálás app.get('/api/user', (req, res) => { const token = req.headers.authorization?.split(' ')[1]; // Token validálás... res.json({ user: userData }); }); \end{verbatim} \end{frame} \begin{frame}[shrink=15]{OAuth 2.0 Security} \begin{enumerate} \item \textbf{HTTPS kötelező}: Minden kommunikáció \item \textbf{State parameter}: CSRF védelem \item \textbf{Redirect URI validation}: Előre regisztrált URI \item \textbf{Short token lifetime}: Access token max 1 óra \item \textbf{PKCE használata}: Mobil/SPA app-okhoz \item \textbf{Scope limitation}: Csak szükséges jogok \end{enumerate} \end{frame}