Tutorial 3.16: OAuth, OpenID Connect, and Modern Identity Systems
Learning Objectives
After completing this tutorial, you should be able to:
- Explain the OAuth 2.0 authorization framework and its core roles and grant types.
- Analyze the OAuth 2.0 authorization code flow, implicit flow, and client credentials flow.
- Evaluate the security properties of OAuth 2.0 and identify common vulnerabilities.
- Define OpenID Connect (OIDC) and its relationship to OAuth 2.0.
- Describe the structure and usage of ID tokens, access tokens, and refresh tokens in OIDC.
- Compare OIDC flows (authorization code, implicit, hybrid).
- Assess modern identity systems, including enterprise IdPs (Azure AD, Okta) and consumer IdPs (Google, Facebook).
- Design an authentication solution using OAuth 2.0 and OIDC for a given application.
- Implement security best practices for OAuth 2.0/OIDC.
- Analyze real-world case studies of OAuth 2.0 and OIDC deployments.
Overview
In the previous tutorials, we explored authentication protocols for network access (RADIUS, TACACS+, Diameter) and
federated identity (SAML). However, the modern web, mobile, and cloud landscape has been shaped by a new set of
protocols: OAuth 2.0 and OpenID Connect (OIDC). These have become the de facto
standards for securing APIs, enabling delegated access, and providing user authentication in web and mobile
applications.
OAuth 2.0 is an authorization framework that allows third-party applications to obtain limited access to a user's
resources without exposing the user's credentials. It is widely used for "Login with Google/Facebook," API access,
and cloud service authorization. OAuth 2.0 defines several grant types (flows) for different client types and use
cases, each with specific security considerations.
OpenID Connect (OIDC) builds on OAuth 2.0 to provide authentication and user identity information. OIDC adds an
ID token (a JWT) that contains claims about the user, enabling single sign-on and user info retrieval.
OIDC has become the standard for modern web and mobile authentication, offering a simpler and more flexible alternative
to SAML.
This tutorial provides a comprehensive exploration of OAuth 2.0, OIDC, and modern identity systems. We begin by
introducing the OAuth 2.0 framework, its roles, and the various grant types. We then dive deep into the authorization
code flow (the most common), the implicit flow (now deprecated), the client credentials flow, and the refresh token
flow. We analyze the security properties and common attacks (e.g., CSRF, redirect URI manipulation, token theft).
We then introduce OpenID Connect, explaining how it extends OAuth 2.0 with the ID token, UserInfo endpoint, and
discovery. We cover the OIDC flows and the semantics of claims. We also discuss modern identity systems, including
enterprise identity providers (Azure AD, Okta) and consumer identity providers (Google, Facebook, Apple).
We provide practical guidance on implementing OAuth 2.0 and OIDC, including best practices for security,
troubleshooting, and integration patterns. The tutorial concludes with case studies illustrating enterprise SSO with
OIDC, mobile app authentication, and API gateway security. By the end, you will have a thorough understanding of the
protocols that power modern identity and access management.
1. Introduction to Modern Identity Systems
1.1 The Shift from Enterprise to Internet-Scale Identity
Traditional enterprise identity was built around on-premises directories (Active Directory) and protocols like
Kerberos and LDAP. The rise of cloud, mobile, and APIs has driven the need for identity systems that are:
- Scalable: Supporting billions of users and devices.
- Interoperable: Working across organizations and platforms.
- User-centric: Providing seamless SSO and consent management.
- Secure: Protecting against modern threats like phishing and token theft.
OAuth 2.0 and OIDC emerged as the foundation for this new paradigm, enabling secure delegated access and
authentication for web, mobile, and IoT.
1.2 OAuth 2.0 vs. OpenID Connect
- OAuth 2.0: Authorization framework. Allows a client to access resources on behalf of a resource
owner (user) using access tokens. It does not provide authentication.
- OpenID Connect (OIDC): Identity layer on top of OAuth 2.0. Adds authentication and user identity
information via the ID token. It provides a standardized way to authenticate users and obtain claims.
In practice, OIDC is often used for authentication, while OAuth 2.0 is used for authorization (API access). They are
commonly used together.
Key Takeaway: OAuth 2.0 and OpenID Connect are the foundational protocols for modern identity systems,
providing delegated authorization and authentication for internet-scale applications.
2. OAuth 2.0 Framework – Deep Dive
2.1 OAuth 2.0 Roles
- Resource Owner: The user who grants access to their resources.
- Client: The application requesting access to the resource owner's resources.
- Authorization Server: The server that authenticates the resource owner and issues access tokens.
- Resource Server: The server hosting the protected resources, capable of validating access tokens.
2.2 Grant Types (Flows)
OAuth 2.0 defines several grant types (flows) based on the client type and use case:
- Authorization Code Grant: The most common, used for server-side web applications. The client
obtains an authorization code, which is exchanged for an access token.
- Implicit Grant: Designed for single-page applications (SPAs) where the client cannot keep a
secret. The access token is returned directly in the redirect. Deprecated in OAuth 2.1.
- Resource Owner Password Credentials Grant: The client uses the user's username and password to
obtain a token. Used for legacy or trusted applications. Deprecated in OAuth 2.1.
- Client Credentials Grant: The client authenticates itself (not on behalf of a user) to obtain a
token for its own resources.
- Refresh Token Grant: Used to obtain a new access token using a refresh token.
2.3 Authorization Code Flow (Detailed)
This is the most secure and recommended flow for web applications. It involves an intermediate authorization code that
is exchanged for tokens, preventing the access token from being exposed in the browser.
- Client redirects user to Authorization Server: Client constructs an authorization URL with
parameters:
response_type=code, client_id, redirect_uri, scope,
state.
- User authenticates and consents: Authorization server authenticates the user and prompts for
consent (if needed).
- Authorization server redirects back with code: Server redirects to the client's redirect URI
with an
code parameter (authorization code) and the state parameter.
- Client exchanges code for tokens: Client makes a POST request to the token endpoint with
grant_type=authorization_code, code, redirect_uri, and client credentials.
- Authorization server returns tokens: Server responds with
access_token,
refresh_token (optional), expires_in, and optionally an id_token (if OIDC).
- Client uses access token to access resources: Client includes the access token in the
Authorization: Bearer header.
// Example token exchange request
POST /token HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=abc123&
redirect_uri=https%3A%2F%2Fclient.example.com%2Fcallback&
client_id=client123&
client_secret=secret456
2.4 Implicit Flow (Deprecated)
In the implicit flow, the access token is returned directly in the redirect URI fragment. This flow was intended for
SPAs, but it has security concerns (token exposure in the browser history, inability to refresh tokens without user
interaction). OAuth 2.1 deprecates the implicit flow in favor of the Authorization Code flow with PKCE.
2.5 Client Credentials Flow
Used for machine-to-machine communication. The client authenticates using its credentials and obtains an access token
that represents the client itself (not a user). This flow does not involve user consent.
2.6 Refresh Token Flow
When an access token expires, the client can use a refresh token to obtain a new access token without user interaction.
Refresh tokens are long-lived and must be stored securely.
2.7 Token Types and Security
- Access Token: A bearer token granting access to protected resources. It should be short-lived
(e.g., 1 hour).
- Refresh Token: Used to obtain new access tokens. It is long-lived and must be stored securely
(e.g., in a secure HTTP-only cookie).
- Bearer Tokens: Any party in possession of the token can use it. Must be transmitted over HTTPS.
- Proof Key for Code Exchange (PKCE): An extension to the authorization code flow to protect against
authorization code interception attacks, especially for public clients (SPAs, mobile).
2.8 OAuth 2.0 Security Considerations
- Redirect URI Validation: Must strictly match the registered redirect URI to prevent code
interception.
- State Parameter: Used to protect against CSRF attacks; must be validated.
- Client Secret Confidentiality: For confidential clients, the secret must be kept secure.
- Token Storage: Access tokens should not be stored in browser local storage (vulnerable to XSS).
Use secure, HTTP-only cookies for refresh tokens.
- Scope Limitation: Request only the necessary scopes.
- Use of HTTPS: All endpoints must use TLS.
Important: OAuth 2.0 is a framework, not a strict protocol. Implementations vary; always follow
security best practices and use well-tested libraries.
3. OpenID Connect (OIDC)
3.1 Introduction and Relationship to OAuth 2.0
OpenID Connect (OIDC) is a simple identity layer built on top of OAuth 2.0. It allows clients to verify the identity
of the end-user based on the authentication performed by an authorization server, as well as to obtain basic profile
information. OIDC is the successor to OpenID 2.0 and is widely adopted.
3.2 OIDC Tokens
- ID Token: A JWT containing claims about the user's identity (e.g.,
sub,
email, name, iss, aud, iat, exp). It is
signed (and optionally encrypted) by the OpenID Provider (OP).
- Access Token: OAuth 2.0 token used to access protected resources (UserInfo endpoint).
- Refresh Token: Optional, used to obtain new tokens.
3.3 OIDC Flows
- Authorization Code Flow: The most secure flow, using an authorization code to exchange for tokens.
Used for server-side web apps.
- Implicit Flow: Tokens are returned directly in the redirect. Deprecated for new applications; use
Authorization Code with PKCE.
- Hybrid Flow: Combines elements of both, allowing some tokens to be returned immediately and
others after exchange. Used for specific scenarios.
In practice, the Authorization Code flow with PKCE is recommended for all clients, including public clients (SPAs,
mobile apps).
3.4 OIDC Claims and Scopes
Claims are pieces of information about the user. Common scopes:
openid: Required, indicates that the client intends to use OIDC.
profile: Basic profile claims (name, family_name, given_name, picture, etc.).
email: Email address and verified status.
address: Physical address.
phone: Phone number.
offline_access: Request a refresh token.
3.5 UserInfo Endpoint
The UserInfo endpoint returns claims about the authenticated user. The client includes the access token in the
request, and the server returns a JSON object with the user's claims.
3.6 OIDC Discovery and Dynamic Registration
OIDC Discovery defines a well-known configuration endpoint (/.well-known/openid-configuration) that
returns the OP's metadata (issuer, authorization endpoint, token endpoint, UserInfo endpoint, JWKS URI, etc.). Dynamic
registration allows clients to register with the OP programmatically.
// Example ID Token (JWT) payload
{
"sub": "1234567890",
"name": "John Doe",
"email": "john@example.com",
"iss": "https://auth.example.com",
"aud": "client123",
"iat": 1311280970,
"exp": 1311284570
}
Key Takeaway: OpenID Connect extends OAuth 2.0 with authentication and user identity, providing a
standardized way to implement SSO and user profile retrieval in modern applications.
4. Modern Identity Systems
4.1 Enterprise Identity Providers (IdPs)
- Azure Active Directory (Azure AD): Microsoft's cloud-based identity service, supports OIDC,
SAML, OAuth 2.0. Provides conditional access, MFA, and integration with on-premises AD.
- Okta: A leading independent identity platform, supports OIDC, SAML, OAuth, and provides
lifecycle management, SSO, and adaptive authentication.
- Ping Identity: Provides enterprise identity solutions, including PingFederate (federation) and
PingOne (cloud).
- Auth0: A developer-friendly identity platform, supports OIDC, OAuth, social login, and custom
extensibility.
4.2 Consumer Identity Providers
- Google Identity: OIDC provider for consumer accounts. Used for "Sign in with Google".
- Facebook Login: OAuth 2.0 and OIDC (limited) provider.
- Apple Sign In: OIDC provider with privacy-focused features.
- Amazon Cognito: AWS's identity service, supports OIDC and social logins.
4.3 Decentralized Identity and Self-Sovereign Identity (SSI)
Emerging paradigm where users own and control their identity data without relying on centralized IdPs. Uses
blockchain and verifiable credentials. Standards: DID (Decentralized Identifiers), Verifiable Credentials (VCs).
OIDC can be extended with SIOP (Self-Issued OpenID Provider) to support SSI.
4.4 Comparison of Identity Providers
| Provider |
Protocols |
Target Audience |
Key Features |
| Azure AD |
OIDC, SAML, OAuth |
Enterprise |
Conditional Access, MFA, AD integration |
| Okta |
OIDC, SAML, OAuth |
Enterprise |
Lifecycle management, adaptive authentication |
| Auth0 |
OIDC, OAuth |
Developers |
Social login, extensibility, tenant support |
| Google |
OIDC, OAuth |
Consumers |
Billions of users, easy integration |
| Facebook |
OAuth |
Consumers |
Social graph integration |
5. OAuth 2.0 and OIDC in Practice
5.1 Implementing an OAuth 2.0 Authorization Server
When building an authorization server, consider using well-established libraries or frameworks (e.g., Spring Security,
OIDC libraries for Node.js, Python, or commercial solutions). Key endpoints:
- Authorization Endpoint: For user authentication and consent.
- Token Endpoint: For exchanging authorization codes and refresh tokens.
- UserInfo Endpoint: For returning user claims (if OIDC).
- JWKS Endpoint: For exposing public keys for token verification.
5.2 Client Integration Patterns
- Server-side Web Apps: Use Authorization Code flow with client secret. Store tokens securely
(server-side session).
- Single-Page Applications (SPAs): Use Authorization Code flow with PKCE. Use HTTP-only cookies
for refresh tokens, access tokens in memory.
- Mobile Apps: Use Authorization Code flow with PKCE using a browser-based flow (e.g., Chrome
Custom Tabs). Store tokens securely using platform secure storage.
- Machine-to-Machine: Use Client Credentials flow.
5.3 Security Best Practices
- Always use HTTPS for all communication.
- Validate redirect URIs strictly.
- Use the
state parameter to prevent CSRF.
- For public clients, use PKCE.
- Keep access tokens short-lived (e.g., 15-60 minutes).
- Store refresh tokens securely (e.g., HTTP-only, secure cookies).
- Validate ID tokens: issuer, audience, expiration, signature.
- Monitor for anomalies (e.g., many token refreshes).
- Use token revocation endpoints when possible.
5.4 Troubleshooting Common Issues
- Invalid redirect URI: Ensure the redirect URI matches the registered value exactly.
- Invalid client credentials: Check client ID and secret.
- Token expired: Use refresh token to obtain a new one.
- Invalid scope: Request scopes that are supported by the authorization server.
- Signature validation failure: Verify the JWKS URI and signature algorithm.
- CORS issues: Ensure the authorization server includes appropriate CORS headers.
6. Case Studies
6.1 Case Study: Enterprise SSO with OIDC
Background: A large enterprise with 15,000 employees uses Azure AD as the central identity provider.
They want to enable SSO for all internal and external applications, including custom web apps, SaaS apps, and mobile
apps. They also need MFA and conditional access.
Solution:
- Azure AD configured as OIDC provider.
- Custom web apps use Authorization Code flow with PKCE.
- SaaS apps (Salesforce, Office 365) integrated via OIDC or SAML.
- Mobile apps use Authorization Code flow with PKCE and use AppAuth libraries.
- Conditional Access policies enforce MFA and device compliance.
- All tokens are validated at the resource server (using JWKS).
Outcome: Employees have seamless SSO across all applications. Security is enhanced with MFA and
conditional access. Administration is centralized.
6.2 Case Study: Mobile App Authentication with OAuth 2.0
Background: A mobile app (iOS/Android) needs to access a backend API. The app must authenticate
users and obtain authorization to access user data. They want to use social login (Google/Facebook) and also support
email/password.
Solution:
- Uses Auth0 as the identity platform.
- Social connections (Google, Facebook) enabled via OIDC.
- Email/password connection via Auth0's database.
- Mobile app uses Authorization Code flow with PKCE.
- App uses a browser-based authentication flow (SFSafariViewController / Chrome Custom Tabs).
- Tokens are stored in the platform's secure storage (Keychain/Keystore).
- Refresh tokens are used to maintain session.
Outcome: Users can sign in with their preferred method. The app securely accesses the backend API.
Refresh tokens keep users logged in across sessions.
6.3 Case Study: API Gateway Security with OAuth 2.0
Background: A microservices architecture with many internal services. They need to secure APIs for
both internal and external clients. They want to use OAuth 2.0 for API authorization.
Solution:
- Deploy an API Gateway that acts as the OAuth 2.0 resource server.
- API Gateway validates access tokens from incoming requests using the authorization server's JWKS.
- Internal services trust the API Gateway and do not perform token validation themselves.
- External clients use OAuth 2.0 client credentials flow to obtain tokens.
- Internal clients (machine-to-machine) also use client credentials.
- Token introspection endpoint used when needed.
Outcome: The API Gateway centralizes security enforcement. Internal services can focus on business
logic. Token validation is efficient and consistent.
7. Future Trends and Evolution
7.1 OAuth 2.1
OAuth 2.1 is an upcoming revision that consolidates and simplifies the OAuth 2.0 specification. It deprecates the
implicit and password grant types, mandates PKCE for public clients, and incorporates best practices. It aims to make
OAuth more secure and easier to implement.
7.2 Token Binding and JWT Best Practices
Token binding ties a token to a specific client context (e.g., TLS session). This can prevent token theft and replay
attacks. JWT best practices include using short-lived tokens, strong signing algorithms (e.g., ES256), and proper
audience validation.
7.3 Decentralized Identity (DID/Verifiable Credentials)
Self-Sovereign Identity (SSI) aims to give users control over their identity data. Standards like DID (Decentralized
Identifiers) and Verifiable Credentials are emerging, and OIDC can be extended with SIOP (Self-Issued OpenID Provider)
to support SSI.
7.4 AI and Identity
AI/ML is being used for risk-based authentication, anomaly detection, and adaptive access control. Identity systems
are becoming more intelligent, adjusting policies based on real-time risk.
Key Takeaway: OAuth 2.0 and OIDC continue to evolve with OAuth 2.1, token binding, and integration
with decentralized identity. Modern identity systems are increasingly intelligent and adaptive.
Quiz
Answer the following questions to check your understanding. Click the "Answer" button to reveal the solution.
Q1. Which OAuth 2.0 role is responsible for authenticating the user and issuing access tokens?
- A) Resource Owner
- B) Client
- C) Authorization Server
- D) Resource Server
Answer
C) The Authorization Server authenticates the resource owner and issues access tokens.
Q2. Which OAuth 2.0 grant type is recommended for server-side web applications?
- A) Implicit Grant
- B) Resource Owner Password Credentials Grant
- C) Authorization Code Grant
- D) Client Credentials Grant
Answer
C) The Authorization Code Grant is recommended for server-side web apps.
Q3. In OpenID Connect, which token contains identity claims about the user?
- A) Access Token
- B) Refresh Token
- C) ID Token
- D) Authorization Code
Answer
C) The ID token contains identity claims about the user.
Q4. Which OAuth 2.0 parameter is used to protect against CSRF attacks?
- A) scope
- B) state
- C) redirect_uri
- D) client_id
Answer
B) The state parameter protects against CSRF attacks.
Q5. Which extension to the Authorization Code Flow prevents authorization code interception attacks?
- A) PKCE
- B) JWT
- C) JWS
- D) OIDC
Answer
A) PKCE (Proof Key for Code Exchange) protects against code interception.
Q6. In OIDC, which endpoint returns additional user claims?
- A) Authorization Endpoint
- B) Token Endpoint
- C) UserInfo Endpoint
- D) JWKS Endpoint
Answer
C) The UserInfo Endpoint returns additional user claims.
Q7. Which OAuth 2.0 grant type is deprecated in OAuth 2.1?
- A) Authorization Code
- B) Client Credentials
- C) Implicit
- D) Refresh Token
Answer
C) The Implicit grant is deprecated in OAuth 2.1.
Q8. Which scope is required to indicate the use of OpenID Connect?
- A) profile
- B) email
- C) openid
- D) offline_access
Answer
C) The openid scope is required for OIDC.
Q9. In OAuth 2.0, which role hosts the protected resources and validates access tokens?
- A) Client
- B) Authorization Server
- C) Resource Server
- D) Resource Owner
Answer
C) The Resource Server hosts protected resources and validates access tokens.
Q10. Which of the following is a common security vulnerability in OAuth 2.0?
- A) Redirect URI manipulation
- B) Strong encryption
- C) Use of HTTPS
- D) Short-lived tokens
Answer
A) Redirect URI manipulation is a common vulnerability.
Q11. Which OIDC flow is recommended for single-page applications (SPAs)?
- A) Implicit Flow
- B) Authorization Code Flow with PKCE
- C) Hybrid Flow
- D) Client Credentials Flow
Answer
B) Authorization Code Flow with PKCE is recommended for SPAs.
Q12. What is the purpose of the refresh token in OAuth 2.0?
- A) To obtain a new access token without user interaction
- B) To authenticate the user
- C) To revoke access
- D) To protect against CSRF
Answer
A) The refresh token is used to obtain a new access token without user interaction.
Exercises
These exercises are designed to help you apply the concepts from this tutorial. Attempt each exercise before revealing the sample solution.
Exercise 3.16-1: OAuth 2.0 Flow Tracing
Describe the complete OAuth 2.0 Authorization Code flow for a web application. Include all steps, parameters, and the security measures in place. Explain what happens if the user denies consent.
Sample Solution
Authorization Code Flow:
- User clicks "Login" -> client redirects to authorization endpoint with
response_type=code, client_id, redirect_uri, scope, state.
- Authorization server authenticates user and prompts for consent.
- If user approves, server redirects to
redirect_uri with code and state.
- Client exchanges code for tokens via POST to token endpoint with
grant_type=authorization_code, code, redirect_uri, and client credentials.
- Server responds with
access_token, refresh_token (optional), expires_in, and (if OIDC) id_token.
- Client uses access token to access resources.
Security: state prevents CSRF; redirect URI validation prevents code interception; client secret ensures only authorized client can exchange code.
Denied consent: Server redirects to redirect_uri with error=access_denied and no code.
Exercise 3.16-2: OIDC ID Token Validation
You receive an ID token from an OIDC provider. Describe the validation steps you must perform on the client side before trusting the identity. Include signature validation, issuer, audience, expiration, and any other relevant checks.
Sample Solution
ID Token Validation Steps:
- Verify the signature using the provider's JWKS (public keys). Ensure the algorithm is appropriate (e.g., RS256).
- Check the
iss (issuer) claim matches the expected provider URL.
- Check the
aud (audience) claim matches the client ID.
- Check the
exp (expiration) claim: token must not be expired.
- Check the
iat (issued at) claim: token should not be from the future (allow some clock skew).
- If a nonce was used in the authentication request, verify it matches.
- Check
auth_time if required.
- Additional checks: verify the
azp (authorized party) if needed.
Exercise 3.16-3: OAuth 2.0 Security Analysis
You are auditing an OAuth 2.0 implementation. List at least five potential security issues you would look for and explain how to mitigate them.
Sample Solution
- 1. Insecure redirect URI validation: Attackers can intercept authorization codes. Mitigation: register full redirect URIs and validate exact match.
- 2. Missing state parameter: CSRF attack. Mitigation: generate and validate state.
- 3. Client secret exposure: In public clients (SPAs, mobile). Mitigation: use PKCE for public clients, never embed secrets in client-side code.
- 4. Token leakage: Access tokens exposed in browser history or logs. Mitigation: use short-lived tokens, avoid storing tokens in local storage; use secure HTTP-only cookies for refresh tokens.
- 5. Weak token signing algorithm: Use strong algorithms (RS256, ES256) instead of HS256 for signed tokens.
- 6. Lack of scope restriction: Request minimal scopes; ensure authorization server enforces scope limits.
Exercise 3.16-4: OIDC Discovery Configuration
An OIDC provider publishes a well-known configuration endpoint. What information does it typically contain? Provide a sample JSON response and explain the purpose of at least five fields.
Sample Solution
OIDC Discovery Document:
{
"issuer": "https://auth.example.com",
"authorization_endpoint": "https://auth.example.com/authorize",
"token_endpoint": "https://auth.example.com/token",
"userinfo_endpoint": "https://auth.example.com/userinfo",
"jwks_uri": "https://auth.example.com/keys",
"response_types_supported": ["code", "id_token", "code id_token"],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256"],
"scopes_supported": ["openid", "profile", "email"],
"claims_supported": ["sub", "email", "name", "picture"]
}
- issuer: The issuer identifier, must match the
iss claim in tokens.
- authorization_endpoint: URL for user authentication and consent.
- token_endpoint: URL for exchanging authorization codes and refresh tokens.
- jwks_uri: URL to retrieve JSON Web Key Set for verifying signatures.
- scopes_supported: List of scopes the provider supports (e.g., openid, profile).
- claims_supported: List of claims the provider can include in ID tokens.
Exercise 3.16-5: OAuth 2.0 Implementation Plan
You are tasked with implementing OAuth 2.0 for a new mobile app that needs to access a backend API. The app will use a third-party identity provider (e.g., Auth0). Outline the steps to integrate OAuth 2.0 (with OIDC) into the mobile app and the backend API. Include considerations for token storage, refresh tokens, and security.
Sample Solution
Mobile App OAuth 2.0 Integration Plan:
- Step 1: Register the app with the identity provider (Auth0). Obtain client ID, configure redirect URI (using a custom URL scheme).
- Step 2: Use a secure authentication library (AppAuth for mobile) to implement Authorization Code Flow with PKCE.
- Step 3: Upon user login, the library opens a browser session (Chrome Custom Tabs/SFSafariViewController) for authentication.
- Step 4: After successful authentication, the app receives an authorization code, which is exchanged for tokens (access token, refresh token).
- Step 5: Store the refresh token in secure platform storage (Keychain/Keystore). Store the access token in memory (or secure storage with short expiry).
- Step 6: For every API request, include the access token in the Authorization header.
- Step 7: When the access token expires, use the refresh token to obtain a new access token silently.
- Step 8: Backend API validates the access token using the provider's JWKS endpoint.
- Step 9: Implement token revocation on logout and security best practices (HTTPS, state parameter, etc.).
Homework
These homework questions require deeper analysis, research, and application. Answer each question comprehensively.
Homework 3.16-1: OAuth 2.0 Security Research
Write a 1,000–1,250 word research paper on OAuth 2.0 security vulnerabilities and mitigations. Include an analysis of the following vulnerabilities:
- Authorization code interception
- CSRF attacks
- Redirect URI manipulation
- Token theft and replay
- Scope escalation
Provide real-world examples and discuss how PKCE, state parameter, and other mitigations address these threats.
Sample Answer
OAuth 2.0 Security: Vulnerabilities and Countermeasures
- Authorization Code Interception: Attacker intercepts the authorization code. Mitigation: PKCE, short-lived codes, strict redirect URI validation.
- CSRF: Attacker tricks user into approving a request. Mitigation: state parameter.
- Redirect URI Manipulation: Attacker uses a malicious redirect to capture code. Mitigation: exact match validation.
- Token Theft: Attacker steals access token. Mitigation: short-lived tokens, HTTPS, token binding.
- Scope Escalation: Client requests more scopes than needed. Mitigation: authorization server enforces scope limits.
Homework 3.16-2: OIDC vs. SAML Comparative Analysis
Write a 1,000–1,250 word analysis comparing OpenID Connect and SAML 2.0 for enterprise SSO. Discuss architectural differences, protocol features, security, and implementation complexity. Provide a decision framework for choosing between them for a new project.
Sample Answer
OIDC vs. SAML for Enterprise SSO
- Architecture: SAML is XML-based, uses complex bindings; OIDC is JSON/JWT, simpler REST.
- Security: Both support signing and encryption; OIDC's JWT is more widely used in modern languages.
- Implementation Complexity: SAML requires more configuration; OIDC is easier for developers.
- Use Cases: SAML for legacy enterprise apps; OIDC for modern web/mobile.
- Decision Framework: Use OIDC for new projects; use SAML when integrating with legacy systems that only support SAML.
Homework 3.16-3: OAuth 2.0 Implementation for an API Gateway
Design and document a solution for securing a microservices architecture using OAuth 2.0 and an API Gateway. Include:
- High-level architecture diagram.
- Token validation strategy (local vs. introspection).
- Client types and grant flows used.
- Security considerations.
- How to handle token revocation and logout.
Sample Answer
API Gateway OAuth 2.0 Security Design
- Architecture: API Gateway acts as Resource Server, validates tokens using JWKS from Authorization Server. Internal services trust the gateway and do not validate tokens.
- Token Validation: Use local validation (JWKS) for performance; use introspection for revocation checks.
- Client Flows: External clients: Authorization Code (for users) or Client Credentials (for machine). Internal services: Client Credentials.
- Security: HTTPS, token expiration, scope enforcement.
- Revocation: Provide a logout endpoint that revokes the refresh token; access tokens are short-lived.
Homework 3.16-4: Decentralized Identity Research
Write a 1,000–1,250 word research paper on Self-Sovereign Identity (SSI) and its relationship to OIDC. Discuss DID (Decentralized Identifiers), Verifiable Credentials, and the role of OIDC in SSI (SIOP). Analyze the benefits, challenges, and potential impact on traditional identity systems.
Sample Answer
Self-Sovereign Identity and OIDC
- SSI: Users own and control their identity data, using DIDs and Verifiable Credentials.
- SIOP (Self-Issued OpenID Provider): An OIDC profile for SSI, allowing users to act as their own IdP.
- Benefits: User control, privacy, portability.
- Challenges: Adoption, scalability, revocation.
- Impact: Could reduce reliance on centralized IdPs and enable new trust models.
Homework 3.16-5: OAuth 2.1 vs. OAuth 2.0
Write a 1,000–1,250 word analysis of OAuth 2.1, the upcoming revision. Explain the key changes from OAuth 2.0, including the removal of implicit and password grants, the mandatory use of PKCE for public clients, and other security improvements. Discuss the implications for existing OAuth 2.0 implementations and migration strategies.
Sample Answer
OAuth 2.1: The Next Generation
- Changes: Deprecation of implicit and password grants, PKCE required for public clients, and removal of less secure practices.
- Implications: SPAs must switch to Authorization Code with PKCE; password grant clients must migrate to other flows.
- Migration: Update clients to use modern flows; use OAuth 2.1-compliant libraries.
- Benefits: Improved security and simplicity.
Summary
This tutorial provided a comprehensive exploration of OAuth 2.0, OpenID Connect, and modern identity systems. We began
by introducing the evolution of identity systems from enterprise-centric to internet-scale, and the roles of OAuth 2.0
and OIDC in this landscape. We then dove deep into the OAuth 2.0 framework, covering its core roles, grant types
(flows), and security considerations. We analyzed the Authorization Code flow in detail, and discussed the deprecated
implicit and password flows, and the client credentials flow.
We then explored OpenID Connect, explaining how it extends OAuth 2.0 with authentication and the ID token. We covered
the structure of ID tokens, the UserInfo endpoint, OIDC flows, and discovery. We also surveyed modern identity systems,
including enterprise providers (Azure AD, Okta) and consumer providers (Google, Facebook), and discussed emerging trends
like decentralized identity (SSI).
Practical guidance was provided on implementing OAuth 2.0 and OIDC, including security best practices and
troubleshooting. The case studies illustrated enterprise SSO with OIDC, mobile app authentication, and API gateway
security, demonstrating real-world applications.
Finally, we looked at future trends, including OAuth 2.1, token binding, and the integration of AI and decentralized
identity. This tutorial has equipped you with a thorough understanding of the protocols that power modern identity and
access management, enabling you to design, implement, and secure applications using OAuth 2.0 and OIDC.
© 2026 COMP400 – Computer and Network Security • School of Computing and Information Systems, TrustOpen University • Unit 3: Authentication and Access Control