01What is Single Sign-On?
Single Sign-On (SSO) allows users to authenticate once and access multiple applications without re-entering credentials. It improves user experience while enhancing security through centralized authentication.
02SSO Protocols Explained
SAML 2.0 (Security Assertion Markup Language)
Best For: Enterprise applications, legacy systems
How It Works:
- User attempts to access Service Provider (SP)
- SP redirects to Identity Provider (IdP)
- IdP authenticates user
- IdP sends SAML assertion to SP
- SP grants access based on assertion
Key Components:
- Assertion: XML document with authentication/authorization data
- Metadata: Configuration exchange between IdP and SP
- Bindings: How messages are transported (HTTP-POST, HTTP-Redirect)
OAuth 2.0 / OpenID Connect
Best For: Modern applications, APIs, mobile apps
How It Works (Authorization Code Flow):
- User clicks login, redirected to IdP
- User authenticates at IdP
- IdP returns authorization code
- Application exchanges code for tokens
- Application uses access token for APIs
Key Components:
- ID Token: JWT containing user identity claims
- Access Token: Token for API authorization
- Refresh Token: Token for obtaining new access tokens
Protocol Comparison
| Feature | SAML 2.0 | OIDC/OAuth 2.0 |
|---|---|---|
| Format | XML | JSON (JWT) |
| Use Case | Enterprise SSO | Modern apps, APIs |
| Mobile Support | Limited | Excellent |
| Complexity | Higher | Lower |
| Token Size | Larger | Smaller |
03Technical Architecture
Components
``` ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ User │────▶│ Browser │────▶│ Application │ └─────────────┘ └─────────────┘ └──────┬──────┘ │ ▼ ┌─────────────┐ │ IdP │ │ (Okta/ │ │ Entra ID) │ └─────────────┘ ```
IdP-Initiated vs SP-Initiated SSO
SP-Initiated (Recommended):
- User visits application first
- Application redirects to IdP
- After auth, IdP redirects back
IdP-Initiated:
- User starts at IdP portal
- Clicks application tile
- IdP sends assertion to SP
04Implementation Steps
Step 1: Choose Your Protocol
Use SAML 2.0 when:
- Integrating with enterprise applications
- Application only supports SAML
- Need attribute-based access control
Use OIDC when:
- Building modern web/mobile apps
- Need API access
- Want simpler implementation
Step 2: Configure Identity Provider
For Okta:
- Create new application integration
- Select SAML 2.0 or OIDC
- Configure SSO URL and entity ID
- Set attribute mappings
- Download metadata/credentials
For Microsoft Entra ID:
- Go to Enterprise Applications
- Create new application
- Configure SSO settings
- Set up user provisioning
- Assign users/groups
Step 3: Configure Service Provider
SAML SP Configuration:
```xml
OIDC Client Configuration:
```javascript // OIDC Configuration const config = { client_id: 'your-client-id', redirect_uri: 'https://app.example.com/callback', response_type: 'code', scope: 'openid profile email', authority: 'https://your-idp.com' }; ```
Step 4: Implement Authentication Flow
OIDC Implementation Example (JavaScript):
```javascript // Redirect to login function login() { const authUrl = `${config.authority}/authorize? client_id=${config.client_id}& redirect_uri=${config.redirect_uri}& response_type=code& scope=${config.scope}& state=${generateState()}`;
window.location.href = authUrl; }
// Handle callback async function handleCallback() { const code = getUrlParam('code');
const tokenResponse = await fetch(`${config.authority}/token\
