Aegis — Scopes & Protocol Mappers

Aegis is the system that controls what information appears in your tokens. It manages client scopes (named collections of claims) and protocol mappers (rules that extract data and inject it into JWTs). Together, they form the contract between your application and FerrisKey: “Grant me this scope, and I guarantee these claims in the token.”

Why Scopes Matter

Without scopes, every token would contain the same set of claims for every client. Aegis gives you fine-grained control:

  • Minimize data exposure — A public mobile app gets sub and email. An internal admin tool gets realm_roles and permissions. Different clients, different claims.
  • Standard compliance — OIDC defines standard scopes (openid, profile, email). Aegis implements them out of the box.
  • Custom claims — Add your own business-specific claims (department, plan tier, feature flags) through custom protocol mappers.

Architecture

graph TD
    CS[Client Scopes] --> PM[Protocol Mappers]
    PM --> JWT[JWT Claims]
    C[Client] --> CSM[Client Scope Mappings]
    CSM --> CS
    U[User] --> PM

The data flow:

  1. A client has client scope mappings — links to specific scopes with a type (Default/Optional)
  2. Each scope contains one or more protocol mappers
  3. During token generation, mappers extract data from the user and produce JWT claims
  4. Claims are assembled into the final token

Scope Types

TypeBehaviorWhen to Use
DefaultAutomatically included in every token for assigned clientsCore claims your app always needs (email, roles)
OptionalOnly included when requested via the scope parameterSensitive data the client requests on demand
NoneAvailable in the system but not assigned to any clientShared scope definitions waiting to be assigned

Standard OIDC Scopes

FerrisKey ships with the standard OpenID Connect scopes pre-configured:

ScopeClaimsType
openidsubDefault
profilepreferred_username, given_name, family_nameDefault
emailemail, email_verifiedDefault
addressaddressOptional
phonephone_number, phone_number_verifiedOptional
offline_accessEnables refresh token issuanceOptional
introspectAllows token introspectionOptional

Real-World Patterns

API Gateway with Role-Based Access

Create a custom scope api_access with a user_realm_role_mapper that includes realm_roles in the token. Your API gateway reads the roles claim and enforces route-level authorization without calling back to FerrisKey.

Multi-Tenant SaaS

Create a custom scope with a hardcoded_claim_mapper that injects the realm name as a tenant claim. Your backend uses this to route requests to the correct tenant database.

Third-Party Integrations

Assign only openid and email as default scopes for third-party clients. They get the minimum data needed. Your first-party clients get profile, roles, and custom scopes as defaults.