Token management with the DataPower Gateway (v5 compatible)

API Connect can use the DataPower distributed cache to manage the token lifecycle that includes when to revoke access rights.

In order to manage tokens with the DataPower® Gateway (v5 compatible), you must set the Token Management Type to Native in your Native OAuth provider configuration. See Configuring token management and revocation for a native OAuth provider when using Cloud Manager or Configuring token management and revocation for a native OAuth provider when using API Manager.

Also, the DataPower quota enforcement server must be enabled on the DataPower Gateway to use the distributed cache to manage tokens. See Quota enforcement.

Token management relies on gateway-peering to distribute the cache for revocation details within a gateway cluster node, and does not propagate across different gateway clusters. In order to enforce token management across different gateway clusters, you must use the external token store and set the Token Management Type to External in your native OAuth provider configuration.

When distributed cache support is enabled, replay protection is provided across the gateway cluster through the quota enforcement server. This support ensures that the same token cannot be reused across the members of the quota enforcement peer group.

Important:
If you have a cluster of DataPower Gateway servers, the OAuth data synchronization behavior across the servers depends on whether or not you enable revocation:
  • If you enable revocation, API Connect uses the DataPower quota enforcement server, and OAuth data is synchronized across the servers. If an access token is obtained from one server, the OAuth data synchronization ensures that the same authorization code cannot be used to obtain an access code from another server. You must ensure that the DataPower quota enforcement server is configured.
  • If you disable revocation, API Connect does not use the DataPower quota enforcement server and OAuth data does not synchronize across the cluster of DataPower Gateway servers. Therefore, to prevent the same authorization code being used to obtain an access code from more than one server you must configure DataPower to synchronize OAuth data across the servers, by using the DataPower Gateway console.

To configure DataPower to synchronize OAuth data, ensure that the DataPower quota enforcement server is configured. For more information, see Configuring the quota enforcement server.

Resource owner revocation

When Resource owner revocation path is selected in the Token Management screen, the configuration inserts two REST API calls to /oauth2/issued.

  • An HTTP GET operation that retrieves a list of all granted permissions for a specific user.
  • An HTTP DELETE operation that revokes an application for a specific user.

The setting inserts header-based security definitions of client ID and client secret as shown in the View permissions example. The API call to revoke a given application for a given user is shown in the Revoke permissions example.

View permissions example
To list all the applications granted by user cn=spoon,o=ibm with username spoon and password spoon using a registered administration application of 5287fe53-8747-438a-8262-681ec75b79c5.
  • Request:
    GET /oauth2/issued
    HTTP/1.1
           Host: apic.ibm.com
           x-ibm-client-id: 5287fe53-8747-438a-8262-681ec75b79c5
           x-ibm-client-secret: E2qM6mG2bX2uC1xT2iN1uU6bT5cV4dN7nW5kM5uP8vL3uF3cT7
           Authorization: Basic c3Bvb246c3Bvb24=
  • Response:
    HTTP/1.1 200 OK
    
    Content-Type: application/json;charset=UTF-8
    
    Cache-Control: no-store
    
    Pragma: no-cache
    
    [
    
    {
    
    "clientId": "5287fe53-8747-438a-8262-681ec75b79c5", => same client id as request
    
    "owner": "cn=spoon,o=ibm",
    
    "clientName": "PetStore Application",
    
    "scope": "listpet",
    
    "issuedAt": 1503327054,
    
    "consentedOn": 1503327054,
    
    "expiredAt": 1503330654,
    
    "refreshTokenIssued": false,
    
    "appId": "d2031f0f27339315333734ab9",
    
    "org": "PetStoreOrg",
    
    "orgTitle": "Katie Pet Grooming Inc",
    
    "orgId": "5887803de4b06e6998c4b2c7",
    
    "provider": "SuperStore",
    
    "providerTitle": "Simon SuperStore",
    
    "providerId": "5887803de4b06e6998c4b2c7",
    
    "catalog": "publicapi",
    
    "catalogTitle": "For public",
    
    "catalogId": "5887803de4b06e6998c4b2d3"
    
    } => delete second item
    
    ]
Revoke permissions example
To revoke application a8746323-9825-a842-8736-abd8202356ac8 by owner cn=spoon,o=ibm.
  • Request
    DELETE /oauth2/issued?client-id=a8746323-9825-a842-8736-abd8202356ac8
    
    HTTP/1.1
    
    Host: apic.ibm.com
    
    x-ibm-client-id: a8746323-9825-a842-8736-abd8202356ac8 => same client id as delete request
    
    x-ibm-client-secret: E2qM6mG2bX2uC1xT2iN1uU6bT5cV4dN7nW5kM5uP8vL3uF3cT7
    
    Authorization: Basic c3Bvb246c3Bvb24=
  • Response
    HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    Cache-Control: private, no-store, no-cache, must-revalidate
    Pragma: no-cache
    
         { "status": "success" }

Client revocation

When Client revocation path is selected in the Token Management screen, the result is the following:

This option inserts one REST API call to /oauth2/revoke, which supports OAuth 2.0 IETF RFC 7009. An HTTP POST operation that an application can send to this API to revoke either an access_token, or refresh_token with token_type_hint as shown in the following examples:

Revoke access_token
  • Request:
    POST /oauth2/revoke 
    HTTP/1.1
    
        Host: apic.ibm.com
    
           x-ibm-client-id: 5287fe53-8747-438a-8262-681ec75b79c5
           x-ibm-client-secret: E2qM6mG2bX2uC1xT2iN1uU6bT5cV4dN7nW5kM5uP8vL3uF3cT7
          Content-Type: application/x-www-form-urlencoded
    
          token_type_hint=access_token&token=AAIHZGVmYXVsdD1-KqwD0Yc3EDn94lSWX14xuR....
  • Response:
    HTTP/1.1 200 OK
          Content-Type: application/json;charset=UTF-8
          Cache-Control: private, no-store, no-cache, must-revalidate
          Pragma: no-cache
    
         { "status": "success" }
Revoke refresh_token
  • Request:
    POST /oauth2/revoke 
    HTTP/1.1
    
        Host: apic.ibm.com
    
           x-ibm-client-id: 5287fe53-8747-438a-8262-681ec75b79c5
           x-ibm-client-secret: E2qM6mG2bX2uC1xT2iN1uU6bT5cV4dN7nW5kM5uP8vL3uF3cT7
          Content-Type: application/x-www-form-urlencoded
    
          token_type_hint=refresh_token&token=........
  • Response:
    HTTP/1.1 200 OK
          Content-Type: application/json;charset=UTF-8
          Cache-Control: private, no-store, no-cache, must-revalidate
          Pragma: no-cache
    
         { "status": "success" }