logo

Are you need IT Support Engineer? Free Consultant

SAP Commerce Cloud – OCC API with Swagger and OAuth authorization code with PKCE

  • By Sanjay
  • 13/10/2026
  • 31 Views



Introduction

Starting with JDK 21, SAP Commerce Cloud introduces a new OAuth flow for end-user authentication. By default, the Swagger interface does not expose a dedicated authentication screen to support this flow. This article provides a concise guide on how to authenticate as an end user directly within Swagger for OCC API testing purposes.

Activation

First you need to activate Swagger.

In local.properties

springdoc.swagger-ui.enabled=true

 In localextensions.xml

<extension name=”swaggerintegration” />

 

OAuth Clients

As mentioned in this following KBA https://me.sap.com/notes/0003738186, you need to create dedicated OAuth clients for swagger usage.

Execute this following Impex in HAC

OAuthClientDetails;clientId[unique=true];resourceIds;scope;authorizedGrantTypes;authorities;clientSecret;registeredRedirectUri;public;requireProofKey
;swagger;;basic;refresh_token,authorization_code,client_credentials;ROLE_TRUSTED_CLIENT;secret;https://localhost:9002/occ/v2/swagger-ui/oauth2-redirect.html;false;true
;swagger_public;;basic;refresh_token,authorization_code;ROLE_TRUSTED_CLIENT;;https://localhost:9002/occ/v2/swagger-ui/oauth2-redirect.html;true;true

From BackOffice, ensure that you have end-user account activated (Login disable : false)

Screenshot 2026-10-13 At 13.22.00.Png

Login

From Swagger : https://localhost:9002/occ/v2/swagger-ui/index.html

Login your swagger client in PKCE mode: swagger / secret 

Screenshot 2026-10-13 At 13.11.15.Png

Then you should be redirected to end-user login page. Enter your end-user credential.

Screenshot 2026-10-13 At 13.25.18.Png

After that, you should be redirected to Swagger interface and ready to test.

Testing

Now you can test OCC API by executing some requests within end-user authorisation. To check that you're correctly recognise, you can run this following query : customer profile.

Screenshot 2026-10-13 At 13.31.55.Png

Note that current is used as user id. True user id is retrieved by SAP Commerce through OAuth token.

Expected output

<?xml version='1.0′ encoding='UTF-8′?>
<user>
<name>Men</name>
<uid>men@hybris.com</uid>
<active>false</active>
<customerId>9cd038f9-2f7b-46d4-9148-58afe9c8806f</customerId>
<displayUid>men@hybris.com</displayUid>
<firstName>Men</firstName>
<lastName>
</lastName>
<selected>false</selected>
</user>

 





Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us on WhatsApp!