Leanpub Header

Skip to main content

Identity Protocols

Engineering SAML, OAuth 2.0, and OpenID Connect

Identity Protocols
This book is 100% completeLast updated on 2026-09-24

Identity protocols are easy to underestimate. This book goes deep into SAML 2.0, OAuth 2.0 and OpenID Connect, showing how they work in practice, where they break and how to build and audit secure systems. With protocol traces, working code and real attack analysis, it is a hands-on guide for engineers working with modern identity.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
207
Pages
About

About

About the Book

Modern identity protocols are complex distributed trust mechanisms. Their security depends not just on cryptographic correctness but on precise coordination across browsers, servers, and networks. This book takes you from first principles through production operations of SAML 2.0, OAuth 2.0, and OpenID Connect. You will find complete protocol traces showing every HTTP request and response, working code examples you can run and study, rigorous analysis of the most important attacks and vulnerabilities, and architectural guidance for real-world deployments. It is written for experienced engineers who need to design, implement, or audit identity systems.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

Engineering SAML, OAuth 2.0, and OpenID Connect

  1. About this book

Introduction

Chapter 1: Identity, Authentication, and Authorization: The Foundations

  1. Principals, Identities, and Accounts
  2. Authentication versus Verification versus Identification
  3. Authorization and the Confused Deputy Problem
  4. Sessions and Their Invariants
  5. The Trust Boundary and What You Can Rely On
  6. From Single Systems to Federation

Chapter 2: The Web’s Authentication Heritage

  1. HTTP Basic and Digest Authentication
  2. Browser Cookies and Session Management
  3. Same-Origin Policy and Cross-Origin Constraints
  4. Forms-Based Authentication and Its Flaws
  5. The Need for Single Sign-On
  6. Early Enterprise SSO Attempts (Kerberos, LDAP, RADIUS)

Chapter 3: Federation and the Trust Model

  1. What Federation Means and Why It Exists
  2. Identity Providers and Service Providers
  3. Centralized versus Distributed Trust
  4. Assertions, Tokens, and the Statement Problem
  5. Metadata and Dynamic Trust
  6. The Role of Humans: Consent and Delegation

Chapter 4: HTTP, the Browser, and the Attack Surface

  1. The HTTP Redirect and State Transfer
  2. Cookie Scoping, SameSite, Secure, and HttpOnly
  3. Cross-Origin Requests and CORS
  4. Post Messages and Client-Side Communication
  5. The Browser as a Hostile Environment
  6. Logging, HSTS, and Transport Security

Chapter 5: SAML 2.0: Architecture and Concepts

  1. SAML’s Origins in Shibboleth and Liberty Alliance
  2. The SAML Vocabulary: Principals, Assertions, and Artifacts
  3. Identity Providers and Service Providers in SAML
  4. Bindings: HTTP-Redirect, HTTP-POST, and HTTP-Artifact
  5. Security Requirements: Signatures, Encryption, and Timestamps
  6. The SAML Processing Model

Chapter 6: SAML 2.0: Protocol Flows and Message Formats

  1. The Authentication Request (AuthnRequest)
  2. The Authentication Response and Asserted Claims
  3. Complete Protocol Trace: SP-Initiated SSO
  4. Complete Protocol Trace: IdP-Initiated SSO
  5. Single Logout (SLO) Flow
  6. Artifact Binding and Resolution

Chapter 7: XML Security for SAML

  1. XML Signature (XMLDSig): Enveloped, Enveloping, Detached
  2. Canonicalization Algorithms and Their Pitfalls
  3. XML Encryption (XMLenc)
  4. Certificate Formats and Key Transport
  5. Signing Assertions versus Enveloping Assertions
  6. Key Discovery from Metadata

Chapter 8: SAML Metadata and Trust Configuration

  1. The EntityDescriptor and Its Children
  2. Endpoints and Bindings in Metadata
  3. Certificate Publication and Key Roles
  4. Entity Categories and Attribute Authority Metadata
  5. Metadata Aggregation and Chaining
  6. Operational Lifecycle: Updates, Revocation, and Rotation

Chapter 9: OAuth 2.0: Delegated Authorization

  1. The Authorization Problem and Delegation
  2. OAuth’s Four Roles
  3. Tokens: Access Tokens, Refresh Tokens, and Their Invariants
  4. Grant Types and What They Represent
  5. Scopes, Permissions, and Resource Boundaries

Chapter 10: OAuth 2.0: Grant Types and Protocol Flows

  1. The Authorization Code Grant
  2. The Implicit Grant (and Why It Is Deprecated)
  3. Client Credentials Grant (Machine-to-Machine)
  4. Resource Owner Password Credentials Grant (and Why It Is Deprecated)
  5. Authorization Code Grant with PKCE
  6. Token Endpoint Authentication Methods

Chapter 11: OAuth 2.0 Security Requirements

  1. TLS Requirements and Certificate Validation
  2. Client Authentication at the Token Endpoint
  3. Redirect URI Validation and Open Redirect Prevention
  4. The State Parameter and CSRF Prevention
  5. Token Endpoint Security
  6. Secure Token Handling and Storage

Chapter 12: OpenID Connect: Identity Layer on OAuth

  1. What OpenID Connect Adds Over OAuth 2.0
  2. The ID Token: Structure, Claims, and Validation Rules
  3. Authorization Code Flow with OpenID Connect
  4. The userinfo Endpoint and Claim Sets
  5. RP-Initiated Logout
  6. Pushed Authorization Requests (PAR)

Chapter 13: JWT, JWS, JWE, and JWK: The Token Formats

  1. JWT Syntax and Claims: Header, Payload, Signature
  2. JWS: Signing Algorithms (RS256, ES256, PS256, etc.)
  3. JWE: Encryption and Key Wrapping
  4. JWK and JWKS: Key Representation and Discovery
  5. Algorithm Confusion and the none Attack
  6. Token Validation: Issuer, Audience, Expiration, and Signature

Chapter 14: OpenID Connect Discovery and Registration

  1. The Authorization Server Metadata Document
  2. The Client Metadata Registration
  3. Well-Known Discovery URLs
  4. Dynamic Client Registration Protocol
  5. Front-Channel versus Back-Channel Discovery
  6. Discovering Supported Algorithms and Constraints

Chapter 15: PKCE: Securing Public Clients

  1. The Public Client Problem
  2. Authorization Code Interception Attack
  3. PKCE: Protocol Mechanics and Code Challenges
  4. PKCE with Authorization Code Flow
  5. PKCE with OIDC
  6. Why PKCE Belongs Everywhere

Chapter 16: Implementing OAuth and OpenID Connect: Authorization Server

  1. Architecture: Endpoints, Storage, and Dependencies
  2. Client Registry and Configuration
  3. The Authorization Endpoint
  4. The Token Endpoint
  5. JWKS and Discovery Endpoints
  6. Running the Server: Setup and Test

Chapter 17: Implementing Relying Parties and Clients

  1. Web App with Authorization Code + PKCE (Backend Session)
  2. Single-Page Application with PKCE
  3. Machine-to-Machine with Client Credentials
  4. Token Validation Middleware
  5. Error Handling and Logging

Chapter 18: Implementing SAML Service Providers

  1. SP Metadata Generation
  2. Authentication Request Construction
  3. Assertion Validation and Signature Verification
  4. SAML Response Processing
  5. Single Logout Handling
  6. Complete SP Implementation Walkthrough

Chapter 19: Advanced OAuth Patterns

  1. Token Introspection Endpoint
  2. Token Revocation
  3. OAuth Token Exchange (RFC 8693)
  4. JWT Secured Authorization Response Mode (JAR/JARM)
  5. Device Authorization Grant (for TVs and IoT)
  6. Mutual TLS Client Authentication

Chapter 20: OAuth and OIDC for APIs

  1. Reference Tokens versus Self-Contained Tokens
  2. The Resource Server as an OAuth Participant
  3. Validating Tokens in API Gateway and Service Mesh
  4. Audience Claims and Multi-API Authorization
  5. Fine-Grained Authorization with Scopes and Claims
  6. API Security: Rate Limiting, CORS, and Transport

Chapter 21: Sessions, Cookies, and Browser Security

  1. Session State Models
  2. Cookie Attributes and Security
  3. CSRF Defense Strategies
  4. Session Fixation and Session Hijacking
  5. Secure Logout and Session Termination
  6. SameSite: How It Helps and Its Limitations

Chapter 22: Authentication Attack Surface: OAuth and OIDC

  1. CSRF and State Parameter Bypass
  2. Login CSRF (Authorization Server CSRF)
  3. Client Authentication Confusion Attacks
  4. Redirect URI Manipulation
  5. ID Token Substitution Attacks
  6. Scope Manipulation and Privilege Escalation
  7. Token Leakage Through URLs
  8. PKCE Downgrade Attacks

Chapter 23: SAML Attack Surface

  1. XML External Entity (XXE) Attacks
  2. XML Signature Wrapping Attacks
  3. Alias and Key Confusion Attacks
  4. Assertion Replay and Forgery
  5. NameID and Attribute Manipulation
  6. Insecure XML Parsing

Chapter 24: Identity Architecture Patterns

  1. Backend-for-Frontend (BFF) Architecture
  2. Microservices and Internal Token Propagation
  3. Multi-Tenant Identity and Isolation
  4. Workload Identity for Kubernetes and Cloud
  5. Enterprise Federation Strategies
  6. SaaS Identity Architecture

Chapter 25: Migration: From SAML to Modern Protocols

  1. Assessing the Current Federation Landscape
  2. Protocol Bridging and Translation
  3. User Migration and Credential Strategies
  4. Parallel Operation During Transition
  5. Breaking Changes and Compatibility
  6. Post-Migration Security Hardening

Chapter 26: Operational Identity Engineering

  1. Key and Certificate Lifecycle Management
  2. Secrets Management and Rotation
  3. Logging and Auditing Without Leaking Credentials
  4. Observability and Debugging Identity Flows
  5. Incident Response for Key Compromise
  6. Availability and Disaster Recovery

Chapter 27: Design Choices and Trade-Offs

  1. SAML versus OIDC: When Each Makes Sense
  2. JWT versus Reference Tokens
  3. Centralized Identity versus Federated versus Hybrid
  4. Symmetric versus Asymmetric Token Validation
  5. Short-Lived versus Long-Lived Tokens
  6. Vendor Lock-In versus Open Standards

Conclusion

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub