_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

OAuth 2.0 — A Complete Guide to Flows

22. 07. 2024 1 min read intermediate

OAuth 2.0 umožňuje aplikacím přístup k zdrojům uživatele bez sdílení hesla. Google Login, GitHub Login — to je OAuth.

Flows

  • Authorization Code + PKCE: Web a mobile (doporučeno)
  • Client Credentials: Machine-to-machine
  • Device Authorization: TV, IoT
  • Implicit (DEPRECATED): Nepoužívat

Authorization Code + PKCE

import hashlib, base64, secrets code_verifier = secrets.token_urlsafe(64) code_challenge = base64.urlsafe_b64encode( hashlib.sha256(code_verifier.encode()).digest() ).rstrip(b’=’).decode()

Exchange code for tokens

token = requests.post(“https://auth.example.com/token”, data={ “grant_type”: “authorization_code”, “code”: authorization_code, “client_id”: “myapp”, “code_verifier”: code_verifier, }).json()

Client Credentials

token = requests.post(“https://auth.example.com/token”, data={ “grant_type”: “client_credentials”, “client_id”: “service-a”, “client_secret”: “secret”, “scope”: “api.read”, }).json()

Key Takeaway

Auth Code + PKCE pro web/mobile, Client Credentials pro M2M. Vždy validujte state, krátká expirace tokenů.

securityoauthautentizaceapi
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.