Extending the Key Manager Interface

Purpose of the Key Manager

In a typical WSO2 API Manager (WSO2 API-M) deployment, different components talk to the KeyManager interface to achieve different tasks. 

For instance,

  • After creating an application in Developer Portal, subscribers would click on the Generate Keys button to register an application.

    Generate Keys

  • At this point, the Developer Portal talks to the KeyManager to create an OAuth client and get the Consumer Key/Secret and the Application Access token.

  • When the Gateway receives a request, it talks to KeyManager and get the token validated. The KeyManager checks if the token is active, and whether the token is usable to invoke the resource being accessed. If the token is valid, the KeyManager sends additional details about the token (i.e., the Throttling Tier for the subscription and Consumer key) to the Gateway in the response. In turn the Gateway uses these details to determine if the request should be passed to the backend or not.

Therefore, the KeyManager interface acts as the bridge between the OAuth Provider and WSO2 API Manager (WSO2 API-M).

Extending the Key Manager Interface

When you need to write your own implementation to plug an external OAuth2 authorization server which will act as the Key Manager, you should implement the KeyManager interface which is a Java extension point in WSO2 API-M.

For this purpose uncomment and update the API Key Manager details under [apim.key_manager] and add the custom class implementation as follows in the <API-M_Home>/repository/conf/deployment.toml file.


The following are the methods that the KeyManager interface uses to carry out operations.

Method Description

Creates a new OAuth application in the Authorization Server.


Updates an OAuth application.


Retrieves an OAuth application.


The Developer Portal calls this method to get a new application Access Token. This method is called when getting the token for the first time and when the Developer Portal needs to refresh the existing token.


Gets details about an access token.


Gets Key Manager implementation from deployment.toml file.


This method will parse the JSON input and add those additional values to the Access Token Request. If it is needed to pass parameters in addition to those specified in the AccessTokenRequest, those parameters can be provided in the JSON input.


You need to use this method when creating an OAuth application in semi-manual mode when you have a consumer key and secret already generated from a Key Manager and you need to map the key and secret with the existing API-M application.


This method creates an Access Token Request using the OAuth Application information. If the token request is null, this method creates a new object, else it modifies the provided Access Token request.


This method is used to read the Key Manager configuration.


This method talks to the APIResource registration endpoint of the authorization server and creates a new resource.


This method retrieves the registered resource by the given API ID.


This method contains information about all the API resources by its resourceId.


Deletes the registered resource based on the API ID.


Deletes mapping records of OAuth applications.


Provides all the Active tokens issued against the provided Consumer Key.


Provides details of the Access Token that is displayed on the Developer Portal.