API Consumer Authentication & Authorization Flow
This section explains how a consumer (developer/application) securely connects to your API proxies through the Developer Portal, obtains credentials, generates OAuth 2.0 bearer tokens, and makes authorized API calls.
Complete Authentication Architecture
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ DEVELOPER PORTAL │
│ (Integrated / Drupal / Custom Portal) │
│ │
│ ┌─────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌─────────────┐ ┌──────────────────┐ ┌────────────────────────────┐ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ Developer │ ──(1)──►│ APPS │──(2)───►│ API PRODUCTS │ │ │
│ │ │ Account │ Register│ │Associate│ │ │ │
│ │ │ │ App │ ┌────────────┐ │ │ ┌──────────────────────┐ │ │ │
│ │ └─────────────┘ │ │Consumer Key│ │ │ │ Product: "Payments" │ │ │ │
│ │ │ │Consumer │ │ │ │ │ │ │ │
│ │ │ │Secret │ │ │ │ • payments-api proxy │ │ │ │
│ │ │ └────────────┘ │ │ │ • oauth2-proxy │ │ │ │
│ │ │ │ │ │ • Quota: 1000/day │ │ │ │
│ │ │ ┌────────────┐ │ │ │ • Env: prod │ │ │ │
│ │ │ │ App: │ │ │ └──────────────────────┘ │ │ │
│ │ │ │ "MyApp" │ │ │ │ │ │
│ │ │ │ │ │ │ ┌──────────────────────┐ │ │ │
│ │ │ │ Products: │ │ │ │ Product: "Orders" │ │ │ │
│ │ │ │ [Payments, │ │ │ │ │ │ │ │
│ │ │ │ Orders] │ │ │ │ • orders-api proxy │ │ │ │
│ │ │ └────────────┘ │ │ │ • oauth2-proxy │ │ │ │
│ │ │ │ │ │ • Quota: 5000/day │ │ │ │
│ │ └──────────────────┘ │ │ • Env: prod │ │ │ │
│ │ │ └──────────────────────┘ │ │ │
│ │ │ │ │ │
│ │ └────────────────────────────┘ │ │
│ │ │ │ │
│ └─────────────────────────────────────────────────────────────────────┼──────────────────┘ │
│ │ │
└────────────────────────────────────────────────────────────────────────┼────────────────────┘
│
▼
┌────────────────────────────────┐
│ API PROXIES │
│ │
│ ┌──────────────────────────┐ │
│ │ oauth2-proxy │ │
│ │ /oauth/token │ │
│ │ (Token Generation) │ │
│ └──────────────────────────┘ │
│ │
│ ┌──────────────────────────┐ │
│ │ payments-api │ │
│ │ /v1/payments │ │
│ │ (OAuthV2 Verify) │ │
│ └──────────────────────────┘ │
│ │
│ ┌──────────────────────────┐ │
│ │ orders-api │ │
│ │ /v1/orders │ │
│ │ (OAuthV2 Verify) │ │
│ └──────────────────────────┘ │
│ │
└────────────────────────────────┘
Step-by-Step Flow
Step 1: Developer Registers on Portal & Creates an App
The developer signs up on the Developer Portal (Integrated Portal, Drupal-based, or a custom-built portal) and creates an application.
Developer ──► Developer Portal ──► Register ──► Create App "MyApp"
│
▼
Portal auto-generates:
• Consumer Key: abc123xyz
• Consumer Secret: secret456def
What happens behind the scenes:
- Apigee creates a Developer entity (email, name, org)
- Apigee creates a DeveloperApp linked to that developer
- A credential pair (Consumer Key + Consumer Secret) is generated
- The app must be associated with one or more API Products
Step 2: App is Associated with API Products
Each API Product defines: - Which API proxies the app can access - Which environments (dev, staging, prod) - Quota limits (e.g., 1000 calls/day) - OAuth scopes allowed - Custom attributes
App: "MyApp"
├── Product: "Payments API"
│ ├── Proxies: [payments-api, oauth2-proxy]
│ ├── Environments: [prod]
│ ├── Quota: 1000 requests/day
│ └── Scopes: [read, write]
│
└── Product: "Orders API"
├── Proxies: [orders-api, oauth2-proxy]
├── Environments: [prod]
├── Quota: 5000 requests/day
└── Scopes: [read]
Step 3: Consumer Generates Bearer Token (OAuth 2.0)
The consumer uses their Consumer Key + Secret to request an access token from the OAuth proxy:
# Token Request (Client Credentials Grant)
curl -X POST https://api.example.com/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=abc123xyz" \
-d "client_secret=secret456def" \
-d "scope=read write"
Response:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "read write"
}
What Apigee does internally:
1. Receives request at oauth2-proxy
2. Validates client_id (Consumer Key) exists
3. Validates client_secret matches
4. Checks the app status is "approved"
5. Identifies which Products are associated with this key
6. Generates an access token and stores the token-to-product mapping
7. Returns the bearer token to the consumer
Step 4: Consumer Makes API Call with Bearer Token
# API Call with Bearer Token
curl -X GET https://api.example.com/v1/payments/txn-001 \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
Step 5: Apigee Validates & Routes the Request
Request arrives at Apigee Runtime
│
▼
┌─────────────────────────────────────────────────────────┐
│ 1. VERIFY OAuth Token │
│ • Is the token valid? (not expired, not revoked) │
│ • Extract: app, developer, products, scopes │
│ │
│ 2. CHECK API Product Authorization │
│ • Is this proxy (payments-api) included in │
│ any product associated with this token? │
│ • Is the request path allowed by the product? │
│ • Is the environment correct? │
│ │
│ 3. ENFORCE Quota │
│ • Check product quota: 1000 requests/day │
│ • Has the app exceeded its limit? │
│ │
│ 4. APPLY Additional Policies │
│ • Spike Arrest (rate limiting) │
│ • Threat Protection (payload inspection) │
│ • Request Transformation (if needed) │
│ │
│ 5. ROUTE to Backend │
│ • Forward request to target endpoint │
│ • https://backend.internal/payments/txn-001 │
└─────────────────────────────────────────────────────────┘
OAuth 2.0 Proxy Configuration
The dedicated OAuth proxy that generates tokens:
<!-- oauth2-proxy/apiproxy/proxies/default.xml -->
<ProxyEndpoint name="default">
<Flows>
<!-- Token Generation Endpoint -->
<Flow name="GenerateToken">
<Condition>(proxy.pathsuffix MatchesPath "/token") and (request.verb = "POST")</Condition>
<Request>
<Step>
<Name>Generate-Access-Token</Name>
</Step>
</Request>
</Flow>
<!-- Token Refresh Endpoint -->
<Flow name="RefreshToken">
<Condition>(proxy.pathsuffix MatchesPath "/refresh") and (request.verb = "POST")</Condition>
<Request>
<Step>
<Name>Refresh-Access-Token</Name>
</Step>
</Request>
</Flow>
<!-- Token Revocation -->
<Flow name="RevokeToken">
<Condition>(proxy.pathsuffix MatchesPath "/revoke") and (request.verb = "POST")</Condition>
<Request>
<Step>
<Name>Revoke-Access-Token</Name>
</Step>
</Request>
</Flow>
</Flows>
<HTTPProxyConnection>
<BasePath>/oauth</BasePath>
</HTTPProxyConnection>
<!-- No backend needed — Apigee handles token generation internally -->
<RouteRule name="noTarget"/>
</ProxyEndpoint>
OAuthV2 Policy — Generate Token:
<!-- policies/Generate-Access-Token.xml -->
<OAuthV2 name="Generate-Access-Token">
<Operation>GenerateAccessToken</Operation>
<ExpiresIn>3600000</ExpiresIn> <!-- 1 hour in ms -->
<SupportedGrantTypes>
<GrantType>client_credentials</GrantType>
</SupportedGrantTypes>
<GenerateResponse enabled="true"/>
</OAuthV2>
Resource Proxy with Token Verification
The actual API proxy that verifies the token before routing:
<!-- payments-api/apiproxy/proxies/default.xml -->
<ProxyEndpoint name="default">
<PreFlow>
<Request>
<!-- Step 1: Verify the Bearer Token -->
<Step>
<Name>Verify-OAuth-Token</Name>
</Step>
<!-- Step 2: Check Quota (auto-resolved from product) -->
<Step>
<Name>Enforce-Product-Quota</Name>
</Step>
<!-- Step 3: Spike Arrest -->
<Step>
<Name>Spike-Arrest</Name>
</Step>
</Request>
</PreFlow>
<HTTPProxyConnection>
<BasePath>/v1/payments</BasePath>
</HTTPProxyConnection>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
</ProxyEndpoint>
OAuthV2 Policy — Verify Token:
<!-- policies/Verify-OAuth-Token.xml -->
<OAuthV2 name="Verify-OAuth-Token">
<Operation>VerifyAccessToken</Operation>
</OAuthV2>
After verification, Apigee populates flow variables:
accesstoken.{token_name}.client_id → abc123xyz
accesstoken.{token_name}.developer.email → dev@example.com
accesstoken.{token_name}.app.name → MyApp
accesstoken.{token_name}.scope → read write
apiproduct.name → Payments API
Quota Policy (product-driven):
<!-- policies/Enforce-Product-Quota.xml -->
<Quota name="Enforce-Product-Quota">
<Distributed>true</Distributed>
<Synchronous>true</Synchronous>
<!-- Values auto-resolved from API Product configuration -->
<Allow countRef="apiproduct.developer.quota.limit" count="1000"/>
<Interval ref="apiproduct.developer.quota.interval">1</Interval>
<TimeUnit ref="apiproduct.developer.quota.timeunit">day</TimeUnit>
<Identifier ref="client_id"/>
</Quota>
Entity Relationships
┌──────────────┐ ┌──────────────────┐ ┌─────────────────────┐
│ DEVELOPER │ │ DEVELOPER APP │ │ API PRODUCT │
│ │ 1───N │ │ N───N │ │
│ • email │───────│ • App Name │───────│ • Product Name │
│ • name │ │ • Consumer Key │ │ • API Proxies [] │
│ • org │ │ • Consumer Secret│ │ • Environments [] │
│ • status │ │ • Products [] │ │ • Quota Limit │
│ │ │ • Status │ │ • Scopes [] │
│ │ │ • Key Expiry │ │ • Access: public/ │
│ │ │ │ │ private/internal │
└──────────────┘ └──────────────────┘ └──────────┬──────────┘
│
N────┼────N
│
┌─────────▼──────────┐
│ API PROXY │
│ │
│ • Proxy Name │
│ • BasePath │
│ • Target Backend │
│ • Policies │
│ • Revision │
└─────────────────────┘
Supported OAuth 2.0 Grant Types
| Grant Type | Use Case | Flow |
|---|---|---|
| Client Credentials | Server-to-server (no user context) | App sends key+secret → gets token |
| Authorization Code | User-facing apps (most secure) | User login → auth code → token exchange |
| Password (ROPC) | Trusted first-party apps | Username+password+key+secret → token |
| Implicit | Legacy SPAs (deprecated) | Redirect → token in URL fragment |
Client Credentials Flow (Most Common for APIs)
┌──────────┐ ┌──────────────┐ ┌──────────────┐
│ Consumer │ │ OAuth Proxy │ │ API Proxy │
│ (App) │ │ /oauth/token │ │ /v1/payments │
└────┬─────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
│ POST /oauth/token │ │
│ grant_type=client_credentials │ │
│ client_id=abc123 │ │
│ client_secret=secret456 │ │
│────────────────────────────────►│ │
│ │ │
│ │ Validate credentials │
│ │ Check app status │
│ │ Resolve products │
│ │ Generate token │
│ │ │
│◄────────────────────────────────│ │
│ {"access_token": "eyJ...", │ │
│ "expires_in": 3600} │ │
│ │ │
│ GET /v1/payments/txn-001 │ │
│ Authorization: Bearer eyJ... │ │
│─────────────────────────────────┼──────────────────────────────────►│
│ │ │
│ │ Verify token │
│ │ Check product access │
│ │ Enforce quota │
│ │ Route to backend │
│ │ │
│◄────────────────────────────────┼───────────────────────────────────│
│ 200 OK {"payment": {...}} │ │
│ │ │
Error Scenarios
| Scenario | HTTP Code | Error |
|---|---|---|
| Invalid Consumer Key | 401 | InvalidApiKey |
| Invalid Consumer Secret | 401 | InvalidClientCredentials |
| Expired Token | 401 | access_token_expired |
| Revoked Token | 401 | access_token_revoked |
| Proxy not in Product | 403 | InvalidApiProductAccess |
| Quota Exceeded | 429 | QuotaViolation |
| App not approved | 401 | DeveloperAppNotApproved |
Portal Types
| Portal | Description | Best For |
|---|---|---|
| Integrated Portal | Built-in Apigee portal (Apigee-managed) | Quick setup, small teams |
| Drupal Portal | Open-source CMS-based portal (Apigee module) | Full customization, large enterprises |
| Custom Portal | Build your own using Apigee Management APIs | Unique branding, existing portals |
All portals interact with Apigee's Management API to create developers, apps, and retrieve credentials.