Handling Authentication

1. Implementing API Key Authentication

LocationExampleNotes
HeaderX-API-Key: sk_...Preferred
Query?api_key=...Logged, avoid
AuthorizationApiKey sk_...RFC style

Example: API key plugin (Kong)

plugins:
  - name: key-auth
    config:
      key_names: [X-API-Key, apikey]
      key_in_header: true
      key_in_query: false
      hide_credentials: true

2. Using Bearer Token Authentication

Example: Bearer token

GET /v1/orders HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIi...
Token TypeValidation
JWTVerify signature locally
OpaqueIntrospect at auth server
PATDatabase lookup

3. Using Basic Authentication

AspectDetail
FormatBasic base64(user:pass)
SecurityHTTPS only (base64 is not encryption)
Use caseInternal tools, machine accounts
Storagebcrypt/argon2 hashed on server

4. Configuring OAuth 2.0 Flow

Grant TypeUse Case
authorization_code + PKCEWeb/SPA/mobile (preferred)
client_credentialsServer-to-server
refresh_tokenRenew access tokens
device_codeTVs, CLIs
password DEPRECATEDLegacy only
implicit DEPRECATEDReplaced by code+PKCE
Client → /authorize?response_type=code&pkce_challenge → IdP
IdP    → Redirect with ?code=...
Client → /token (code + verifier) → IdP
IdP    → access_token + refresh_token
Client → API (Bearer access_token)
      

5. Implementing JWT Validation

ClaimValidation
issMatch issuer URL
audMatch expected audience
expFuture timestamp
nbfPast or current
iatReasonable past
SignatureJWKS public key (RS256/ES256)

Example: JWT plugin config

plugins:
  - name: jwt
    config:
      key_claim_name: iss
      claims_to_verify: [exp, nbf]
      secret_is_base64: false
      maximum_expiration: 3600
      run_on_preflight: false

6. Configuring HMAC Signature Validation

Example: HMAC signed request

Authorization: Hmac username="acme",
  algorithm="hmac-sha256",
  headers="(request-target) date digest",
  signature="base64sig=="
Date: Wed, 18 May 2026 12:00:00 GMT
Digest: SHA-256=abcd...

7. Implementing Multi-Factor Authentication

FactorExamples
KnowledgePassword, PIN
PossessionTOTP, SMS, push, hardware key
InherenceBiometric (Face/Touch ID)
Step-up MFARequire on sensitive operations
ACR claimJWT acr = auth level

8. Setting Up Identity Provider Integration (OIDC)

Example: OIDC plugin

plugins:
  - name: openid-connect
    config:
      issuer: https://auth.example.com/realms/api
      client_id: gateway
      client_secret: ${OIDC_SECRET}
      scopes: [openid, profile, email]
      auth_methods: [authorization_code, bearer, introspection]
      bearer_token_param_type: [header]
      cache_introspection: true
      introspection_endpoint_auth_method: client_secret_basic

9. Configuring Anonymous Access

SettingEffect
anonymous: guestFall through to consumer
Public routeNo auth plugin
Optional authEnrich if present, allow if not
Rate limitLower for anonymous

10. Implementing Token Revocation

MechanismNotes
RFC 7009 /revokeOAuth standard
Revocation list (CRL)Polled blocklist
IntrospectionAlways check at /introspect
Short TTL5-15 min limits damage
Refresh rotationOne-time use refresh tokens