Generate keys¶
What happens
A developer clicks Generate Keys for an application. APIM asks a Key Manager to create an OAuth client (a consumer key and secret) for that application and key type (Production or Sandbox). With the built-in Resident Key Manager, the OAuth client is stored in the Identity Server tables. APIM then records the link between the application and the client in AM_APPLICATION_KEY_MAPPING.
Who: Developer Portal → Key Manager · Tables written: AM_APPLICATION_REGISTRATION, AM_APPLICATION_KEY_MAPPING, IDN_OAUTH_CONSUMER_APPS, IDN_OIDC_PROPERTY, SP_APP, SP_INBOUND_AUTH, SP_METADATA, UM_HYBRID_ROLE, UM_HYBRID_USER_ROLE, IDN_OAUTH2_ACCESS_TOKEN, IDN_OAUTH2_ACCESS_TOKEN_SCOPE, AM_WORKFLOWS (only with approval) · Tables read: AM_APPLICATION, AM_KEY_MANAGER
The flow at a glance¶
This diagram shows key generation with the Resident Key Manager and no approval step.
sequenceDiagram
actor Dev as Developer
participant Portal as Dev Portal
participant KM as Resident Key Manager
participant DB as Database
Dev->>Portal: Generate Production keys
Portal->>DB: insert AM_APPLICATION_REGISTRATION
Portal->>KM: create OAuth client
KM->>DB: insert SP_APP, SP_INBOUND_AUTH, app role
KM->>DB: insert IDN_OAUTH_CONSUMER_APPS
Portal->>DB: insert AM_APPLICATION_KEY_MAPPING (COMPLETED)
KM->>DB: insert first access token
Portal-->>Dev: consumer key, secret, token
- All of these rows are written as part of one request. The end state is one mapping row per app, key type and key manager, pointing at one OAuth client.
Step by step¶
-
Pick the Key Manager.
AM_KEY_MANAGERlists the key managers configured for the tenant. The built-in one isResident Key Manager. Others, such as Keycloak or Okta, are registered in the Admin Portal, with their connection details inCONFIGURATION. -
Registration request →
AM_APPLICATION_REGISTRATION. APIM records every key-generation request here, whether or not an approval workflow is on. The stored request includes the grant types, callback URL, token scope and validity. With the Application Registration workflow on, anAM_WORKFLOWSrow is added too, and the keys wait for approval.REG_IDSUBSCRIBER_IDWF_REFAPP_IDTOKEN_TYPETOKEN_SCOPEALLOWED_DOMAINSVALIDITY_PERIODKEY_MANAGER1 1 b21d…2 PRODUCTIONdefaultALL0 Resident Key ManagerINPUTSholds{"tokenScope":"default","validityPeriod":"3600","grant_types":"client_credentials,password","key_type":"PRODUCTION","username":"admin",…}.TOKEN_TYPEhere means the key type (PRODUCTIONorSANDBOX).WF_REFis a UUID that links the request to itsAM_WORKFLOWSrow when a registration workflow is used (logical). It's filled even without a workflow.- FKs: to
AM_SUBSCRIBERandAM_APPLICATION(APP_ID), bothRESTRICT. - The row is not removed once the keys are generated. It stays until the application is deleted.
-
OAuth client in the Key Manager. With the Resident KM, this writes Identity Server tables in the APIM database:
SP_APP: a service provider namedadmin_PizzaApp_PRODUCTION(<owner>_<app>_<keytype>), plus a fewSP_METADATArows.SP_INBOUND_AUTH: says "this service provider uses OAuth2" (INBOUND_AUTH_KEY= the consumer key,INBOUND_AUTH_TYPE = 'oauth2',APP_ID=SP_APP.ID).IDN_OAUTH_CONSUMER_APPS: the OAuth client itself, with about 10 OIDC settings inIDN_OIDC_PROPERTYkeyed by the consumer key.- An application role in
UM_HYBRID_ROLE(Application/admin_PizzaApp_PRODUCTION), assigned to the owner inUM_HYBRID_USER_ROLE.
IDCONSUMER_KEYAPP_NAMEUSERNAMETENANT_IDGRANT_TYPESCALLBACK_URLAPP_STATE2 1BDH…admin_PizzaApp_PRODUCTIONadmin-1234 client_credentials password''ACTIVEThe consumer secret is stored in
CONSUMER_SECRET. By default it's stored in plain text. Encryption or hashing must be switched on explicitly. With a third-party KM, none of these rows exist in APIM. The client lives in the external system.Row
ID = 1in the test database was the REST client used to drive the test, not an APIM application. Every OAuth client, including the ones behind the portals, lives in this same table. -
The link →
AM_APPLICATION_KEY_MAPPING.APPLICATION_IDKEY_TYPEKEY_MANAGERCONSUMER_KEYSTATECREATE_MODEUUID2 PRODUCTIONResident Key Manager1BDH…COMPLETEDCREATED2485…Generating Sandbox keys adds a second row with
KEY_TYPE = 'SANDBOX'.- The PK is
(APPLICATION_ID, KEY_TYPE, KEY_MANAGER): one set of keys per app, per key type, per key manager. STATEisCREATEDwhile waiting orCOMPLETEDwhen done.CREATE_MODEisCREATED(APIM generated the client) orMAPPED(the developer mapped an existing client with Provide Existing OAuth Keys).APP_INFOholds extra client details returned by the Key Manager.- FK to
AM_APPLICATIONwithON DELETE RESTRICT.
Logical links (no foreign key)
CONSUMER_KEY→IDN_OAUTH_CONSUMER_APPS.CONSUMER_KEY. This is the bridge between APIM applications and OAuth, and it's matched by value only.KEY_MANAGER→AM_KEY_MANAGER. In 3.2 this holds the key manager's name. 4.x moved to the UUID, so check your data.
- The PK is
-
First access token →
IDN_OAUTH2_ACCESS_TOKEN+IDN_OAUTH2_ACCESS_TOKEN_SCOPE. In 3.2 the Dev Portal's Generate Keys also issues an application token right away (grant typeclient_credentials,USER_TYPE = 'APPLICATION', scopesam_application_scopeanddefault) and stores it. See Get a token & call the API. -
Allowed domains (optional) →
AM_APP_KEY_DOMAIN_MAPPING(CONSUMER_KEY,AUTHZ_DOMAIN). This is a legacy list of domains allowed to use the key, and it wasn't written in the test run. The allowed domains ended up inAM_APPLICATION_REGISTRATION.ALLOWED_DOMAINS(ALL) instead.
What gets cleaned up¶
- Removing keys, or deleting the app: APIM deletes the OAuth client from the Key Manager. That cascades inside the IDN tables: tokens and codes are removed via
IDN_OAUTH2_ACCESS_TOKEN → IDN_OAUTH_CONSUMER_APPS ON DELETE CASCADE. APIM itself deletes theAM_APPLICATION_KEY_MAPPINGandAM_APPLICATION_REGISTRATIONrows (RESTRICTon the application). Deleting the app also removes theSP_*rows, the OIDC properties and theApplication/…hybrid role. - Regenerating the secret updates
IDN_OAUTH_CONSUMER_APPS.CONSUMER_SECRET. The mapping row doesn't change.
Try it¶
This query finds the OAuth client behind each application key.
SELECT app.NAME AS application, km.KEY_TYPE, km.KEY_MANAGER, km.STATE,
oc.CONSUMER_KEY, oc.APP_NAME AS oauth_app, oc.GRANT_TYPES
FROM AM_APPLICATION app
JOIN AM_APPLICATION_KEY_MAPPING km ON km.APPLICATION_ID = app.APPLICATION_ID
LEFT JOIN IDN_OAUTH_CONSUMER_APPS oc ON oc.CONSUMER_KEY = km.CONSUMER_KEY
WHERE app.NAME = 'PizzaApp';
A NULL in the oc.* columns means the client lives in an external Key Manager.
Related domains: Keys & tokens · Applications & subscriptions
Different in 4.x
In 4.x, AM_KEY_MANAGER is scoped by ORGANIZATION and gains TOKEN_TYPE and EXTERNAL_REFERENCE_ID. Key manager permissions get their own table, and client secrets can live in IDN_OAUTH_CONSUMER_SECRETS (multiple secrets per client). See Generate keys (4.x).