# How to create OAuth 2.0 access token to call Pega API

**URL:** <https://forums.pega.com/t/how-to-create-oauth-2-0-access-token-to-call-pega-api/9477>\
**Category:** Knowledge Share\
**Tags:** sales-consultant, sales-manager, manufacturing, enterprise-application-development, pega-cloud, dx-api, government, insurance, consumer-services, other-industry, business-architect, communications-and-media, financial-services, team-lead, pega-delivery-leader, dev-designer-studio, cross-industry, healthcare-and-life-sciences, all-products, ui-solutions-developer, solutions-consulting-manager, solutions-consultant, solutions-engineer, pega-infinity, security, data-management, data-model, senior-system-architect, data-integration, system-architect, lead-system-architect, case-management\
**Created:** [May 14, 2025, 10:27am UTC](https://forums.pega.com/t/how-to-create-oauth-2-0-access-token-to-call-pega-api/9477 "2025-05-14T10:27:30Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kashif\_Minhaj\_P\_K](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@Kashif\_Minhaj\_P\_K](https://forums.pega.com/u/Kashif_Minhaj_P_K)\
**Post date:** [July 11, 2026, 8:54pm UTC](https://forums.pega.com/t/how-to-create-oauth-2-0-access-token-to-call-pega-api/9477/21 "2026-07-11T20:54:24Z")

</div>

Dear @MadhuSudan_Kaka ,

Custom Approach: Issuing JWT Bearer Tokens for Non-Existent Operators

**Background / Problem Statement**

As far as I’m aware, Pega does not currently offer an out-of-the-box (OOTB) supported pattern to issue JWT Bearer tokens when the corresponding Operator ID does not already exist in the system. I raised a support ticket with Pega on this specific scenario, and their response confirmed that no such supported pattern exists today.

Given this gap, I implemented a custom approach — conceptually aligned with the design discussed above — to handle JWT Bearer token issuance for cases where the Operator record needs to be dynamically provisioned at authentication time, rather than pre-provisioned in advance.

**Solution Overview**

The core idea is to leverage the standard Identity Mapping and Claims processing flow, but extend the post-processing logic to check for Operator existence and provision the Operator on-the-fly if it’s not found, before completing the authentication context.

**Detailed Steps**

1. **Token Reception**  
The JWT is received from the client system as part of the Bearer token authentication request.
2. **Token Validation (Identity Mapping)**  
Within the Identity Mapping rule, complete the standard token validation — signature verification, expiry, issuer, and audience checks as per your configured Authentication Service.
3. **Token Profile Processing**  
Process the token profile through the standard sequence:
  - **Claims Validation** — verify the required claims are present and well-formed.
  - **Claims Mapping** — map the incoming JWT claims to the `claimsMappingPage` structure.
  - **Security Check** — apply any additional security/authorization checks as configured.

4. **Operator Identification via Custom Claim**  
Since the Operator doesn’t pre-exist, map a custom claim from the token to a static/deterministic value that can be used as the Operator ID — for example, `{Client Name}`. This value should correspond to a **Service Operator** already created in Pega, which will act as the template/reference identity for provisioning.
5. **Override Processing Activity**  
In the Processing options of the Identity Mapping, override the default activity with a custom activity in your application ruleset — e.g., `pyJWTBearerIdentityMappingAct`. This gives you a hook to inject custom logic into the standard flow.
6. **Retrieve Operator ID from Claims**  
Within the custom activity, retrieve the actual Operator ID from `claimsMappingPage.pyUserIdentifier`. This is the identifier that should represent the “real” Operator for this authenticated session.
7. **Operator Existence Check**  
Perform an `Obj-Open` (or equivalent existence check, e.g., `Obj-Open-By-Handle`/`Exists-In-DB`) on the Operator ID retrieved above.
  - **If the Operator exists:** proceed with the standard flow.
  - **If the Operator does not exist:** dynamically provision a new Operator record using the **Model Operator** as a template, populating the required attributes (Operator ID, access group, work group, etc.) from the token claims / Service Operator defaults.

8. **Persist the New Operator**  
Save the newly created Operator record to the database.
9. **Re-establish Operator Context**  
After saving, perform an `Obj-Open` on the newly created Operator record, targeting it explicitly to the **“Operator” step page**. This replaces the in-memory Operator page (which, up to this point, still referenced the Service Operator) with the details of the newly provisioned Operator. As a result, the JWT/session token generated by Pega at the end of the authentication flow carries the context of the **newly created Operator** , rather than the placeholder Service Operator used during the intermediate steps.

**Outcome**

This approach effectively decouples Operator provisioning from the authentication flow’s dependency on pre-existing Operator records, allowing just-in-time Operator creation driven entirely by validated JWT claims — while still working within Pega’s standard Identity Mapping and Authentication Service framework.

[Previous page](https://forums.pega.com/t/how-to-create-oauth-2-0-access-token-to-call-pega-api/9477.md?page=1)
