‎2024 Dec 07 4:03 PM - edited ‎2024 Dec 07 4:18 PM
Dear All,
In SAP Integration Suite, Basic Authentication offers a simple way to safeguard your API proxies using a username and password. This blog covers how to configure Basic Authentication for your API proxy in API Management.
Follow the Below Steps to Set Basic Authentication to your API Proxy.
Step 1 : Create a Proxy with your target endpoint (For test purpose i used httpbin URL)
https://httpbin.org/get
Step 2 : Go to Policies and Assign Basic Authentication in PreFlow Incoming request Stream
Provide the below code in the policy editor:
<BasicAuthentication async='true' continueOnError='false' enabled='true' xmlns='http://www.sap.com/apimgmt'>
<Operation>Decode</Operation>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<User ref='current.username'></User>
<Password ref='current.password'></Password>
<Source>request.header.Authorization</Source>
</BasicAuthentication>
Step 3 : Add Raise Fault Policy in PreFlow Incoming Stream (Next to the Basic Authentication Policy)
<RaiseFault async="true" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="application/json">{"status" : "Error", "messege" : "401 Unauthorized" } </Payload>
<StatusCode>401</StatusCode>
<ReasonPhrase>Unauthorized</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
In RaiseFault Policy ConditionString Provide below Code (Replace "YOUR_USERNAME" & "YOUR_PASSWORD" with your credentials)
(current.username != "YOUR_USERNAME") OR (current.password != "YOUR_PASSWORD")
Save and Deploy.
Testing :
To Test the Basic Authentication Try a GET Call for Your API Proxy in PostMan:
Positive Testing :
Provide the exact Username and Password given in the Condition String :
Negative Testing :
Provide an incorrect username and password to verify if access is correctly denied.
Incorrect Username :
Incorrect Password :
Thank You!
Request clarification before answering.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.