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=trueIn 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)
Login
From Swagger : https://localhost:9002/occ/v2/swagger-ui/index.html
Login your swagger client in PKCE mode: swagger / secret
Then you should be redirected to end-user login page. Enter your end-user credential.
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.
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
