The short version
Most APEX upgrades break nothing in REST integrations. APEX 26.2 has one exception worth checking: custom OAuth token code.
- The change. APEX 26.2 “now enforces proper token re-use between calls and abides by the scope matching rules”.
- What fails. A token you requested by hand for one scope, set for later calls, and then used for a request that needs a different scope. APEX does not use it.
- The fix. Make the scopes of hand-requested tokens match the Web Credential and the request, or better, let APEX get the token declaratively.
- The audit. Search your code for the token-setting API and hand-built token requests before you upgrade.
What Oracle says changed
The Changed Behavior entry, “Increased Security When Using Scopes and Tokens for OAuth Authentication of REST Web Service Calls”, warns that calls made with “non-standard code to handle OAuth authentication” may fail. Oracle’s example has three steps:
- An OAuth token is requested by hand using
APEX_WEB_SERVICE.MAKE_REST_REQUESTwith a specific scope. - The token is set by hand with the token-setting API.
- The actual REST request, which requires a different scope, is made.
“If the scope of the manually-requested token does not match the scope of the actual REST request, the APEX engine does not use it.” Oracle’s direction is clear: fix custom code “so that OAuth scopes of manually requested tokens match scopes defined in the Web Credential and scopes used for making the REST request”, and “use declarative OAuth authentication instead of custom code whenever possible.”
A naming note before you search: the release notes call the setter APEX_WEB_SERVICE.SET_OAUTH_TOKEN, but the API reference documents APEX_WEB_SERVICE.OAUTH_SET_TOKEN. Search for both spellings.
The failing pattern
A hypothetical example of the kind of code Oracle describes. The token comes from a hand-built request for erp.read, and a later call needs erp.write:
-- Hypothetical: token requested by hand for one scope
l_token_json := apex_web_service.make_rest_request(
p_url => 'https://idp.example.com/oauth2/token',
p_http_method => 'POST',
p_body => 'grant_type=client_credentials&scope=erp.read' );
-- client authentication omitted
apex_web_service.oauth_set_token(
p_token => json_value( l_token_json, '$.access_token' ) );
-- ... then used for a call that needs another scope
l_orders := apex_web_service.make_rest_request(
p_url => 'https://erp.example.com/api/orders',
p_http_method => 'POST',
p_body => l_order_json,
p_oauth_scope => 'erp.write' );
Under 26.2’s rules, the erp.read token is not used for the erp.write call. Code like this tends to live in old integration packages that nobody has touched since they worked.
The declarative fix
Let APEX request and reuse the token. A Web Credential of type OAuth2 Client Credentials holds the client ID, secret and scope, and MAKE_REST_REQUEST can reference it:
l_orders := apex_web_service.make_rest_request(
p_url => 'https://erp.example.com/api/orders',
p_http_method => 'POST',
p_body => l_order_json,
p_credential_static_id => 'ERP_CRED',
p_token_url => 'https://idp.example.com/oauth2/token',
p_oauth_scope => 'erp.write' );
The documented behavior for p_oauth_scope: “APEX uses or requests an access token with the specified scope. Separate multiple scopes with blanks.” With OAuth2 Client Credentials, “If the access token is expired, APEX will transparently request a new one”, and a refresh token is used when the server issued one.
Scopes on the Web Credential
For OAuth2 Client Credentials, the Web Credential’s OAuth Scope is what APEX sends to the token server, in a request body of the form grant_type=client_credentials&scope={scope}. Three related details:
- Named Scopes. “Named Scopes are alias names for OAuth Scopes. When invocations or token requests use the alias name, Oracle APEX will use the Scope Value instead.” Useful when the real scope strings are long or differ between environments.
- Changing a scope.
APEX_CREDENTIAL.SET_SCOPEchanges the scope attribute, and “all existing tokens for the given credential are cleared”. - REST Data Sources. Declarative OAuth there means selecting the stored credential, and an Authentication Server remote server when authentication runs on a different server.
Oracle does not spell out whether scope matching is exact or allows a subset, so treat every distinct scope as its own token and test each call.
Finding affected code
- Database packages. Search the source of your integration schemas, for example with
select owner, name, type, line from all_source where upper(text) like '%OAUTH_SET_TOKEN%', and repeat forSET_OAUTH_TOKEN,OAUTH_GET_LAST_TOKENand your token URLs. - Application code. Search processes, computations and dynamic actions in App Builder, or grep your APEXlang export.
- Hand-built token requests. Look for
grant_type=client_credentialsin request bodies. Those are the calls Oracle’s example describes. - Staging. Run every integration once on 26.2 before production, including scheduled jobs and automations that only run at night.
Our APEX 26.2 upgrade checklist lists this change with the other behavior changes to test.
A short checklist
- Code search done for both setter spellings and hand-built token requests
- Each custom token’s scope compared with the Web Credential and the call
- Custom token code replaced with
p_credential_static_idandp_oauth_scopewhere possible - Multiple scopes separated with blanks
- Named Scopes for long or environment-specific scope strings
- Every integration exercised on a 26.2 staging instance, scheduled jobs included
Upgrades are where integrations quietly fail. For managed APEX environments with staged upgrades and support, see Cloud Hosting and the plans page.
Bottom line
APEX 26.2 stops reusing OAuth tokens across scopes, which is the secure behavior. The price is paid by old custom token code, and the fix is usually to delete it: reference a Web Credential, pass the scope, and let APEX manage tokens.
Search before you upgrade, not after the first nightly job fails.
FAQ
What changed for OAuth in APEX 26.2?
APEX now enforces proper token reuse between calls and the scope matching rules. A token requested by hand for one scope is not used for a request that needs a different scope.
Is the API SET_OAUTH_TOKEN or OAUTH_SET_TOKEN?
The API reference documents APEX_WEB_SERVICE.OAUTH_SET_TOKEN. The 26.2 release notes refer to SET_OAUTH_TOKEN. Search for both.
How should I pass several scopes?
Separate them with blanks, as the MAKE_REST_REQUEST and OAUTH_AUTHENTICATE_CREDENTIAL references describe.
Do I have to write token code at all?
Usually not. With an OAuth2 Client Credentials Web Credential, APEX requests the token, reuses it and gets a new one when it expires. Oracle recommends declarative OAuth whenever possible.
Does changing a Web Credential’s scope affect existing tokens?
Yes. APEX_CREDENTIAL.SET_SCOPE clears all existing tokens for that credential.
Are REST Data Sources affected?
Declarative REST Data Sources that use a stored credential are the path Oracle recommends. The change targets custom code that sets tokens by hand, but test every integration on 26.2 anyway.
Sources
- Oracle APEX 26.2 Release Notes: Changed Behavior
- APEX_WEB_SERVICE.MAKE_REST_REQUEST Function (APEX 26.2)
- APEX_WEB_SERVICE.OAUTH_SET_TOKEN Procedure (APEX 26.2)
- APEX_WEB_SERVICE.OAUTH_AUTHENTICATE_CREDENTIAL Procedure (APEX 26.2)
- APEX_WEB_SERVICE.OAUTH_GET_LAST_TOKEN Function (APEX 26.2)
- APEX_CREDENTIAL.SET_SCOPE Procedure (APEX 26.2)
- Creating Web Credentials (APEX 26.2)
- Understanding Web Credentials (APEX 26.2)
- Editing or Deleting a REST Data Source (APEX 26.2)