sidon.dev

oidc-sso.md · sidon.dev

Decoupled, reusable corporate OIDC/SSO authentication

Part of: Senior Developer · Backend & AI, Petrobras

I wrote the technical story (acceptance criteria, DoR and DoD) and implemented corporate authentication for an AI web application using OpenID Connect (Authorization Code + BFF).

  • Tokens stay on the server only; the browser receives just an opaque session cookie (HttpOnly, Secure, SameSite).
  • The id_token is fully validated: JWKS signature, iss, aud, nonce and exp.
  • Protection against CSRF (signed, short-lived state), session fixation (session ID regenerated at login) and replay.
  • The access_token is renewed transparently through the refresh_token, and logout is integrated with the SSO.
  • Resource-level authorization is checked against the identity provider, with an audit trail of who ran each analysis.
  • Identity provider failures show a friendly error page with a correlation ID and expose no internal details.

The module has no coupling to the application: it is a pure ASGI middleware with injectable dependencies, so it can be extracted as a reusable package. The work supports the area’s goal of standardizing authentication and the edge layer (reverse proxy) for applications going to production. Known limitations, such as in-memory sessions on a single instance and PKCE, are recorded as technical debt, each with the condition for revisiting it.

  • Python
  • ASGI
  • OpenID Connect
  • OAuth 2.0