How to add basic authentication in API Management

Vamshi Kishore KALIKOTA 51 Reputation points
2020-12-01T07:32:31.127+00:00

For details, we are setting an inbound policy where REST service is converted to Soap.
So here, we need to add basic authentication for the URL in the frontend part and in the backend we have Azure Logic App which gets triggered when APIM-Request URL is called from SoapUI.

Below is our code which we have used in the inbound section of APIM :

<policies>
<inbound>
<base />
<set-method id="apim-generated-policy">POST</set-method>
<rewrite-uri id="apim-generated-policy" template="/manual/paths/invoke/?api-version=2016-06-01&sp=/triggers/manual/run&sv=1.0&sig={<!-- -->{ala-barcoding-grn_manual-invoke_5fb3af363b4e13318c5c3994}}" />
<set-header id="apim-generated-policy" name="Ocp-Apim-Subscription-Key" exists-action="delete" />
<set-variable name="barcodegrn" value="@(context.Response.Headers.GetValueOrDefault("SOAPAction","https://interface.com:443/workflows/"))" />
<choose>
<when condition="@(context.Variables.GetValueOrDefault<string>("barcodegrn")
=="https://interface.com:443/workflows/")">
<set-backend-service base-url="https://prod-91.westeurope.logic.azure.com:443/workflows/***********************/triggers/" />
<set-body template="liquid">
{
"insert_BARCODING_GRN":
{
"GR_NUMBER" : "{<!-- -->{body.envelope.body.barcodegrn.input.GR_NUMBER}}",
"GR_ITEM" : "{<!-- -->{body.envelope.body.barcodegrn.input.GR_ITEM}}",
"MATERIAL_DOC_YEAR": "{<!-- -->{body.envelope.body.barcodegrn.input.GR_ITEM}}"
}
}
</set-body>
</when>
</choose>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

So, in the above code we need to add basic authentication code.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,175 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,211 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Koerner 1 Reputation point
    2020-12-01T16:33:54.513+00:00

    Try adding this to the inbound policy
    <authentication-basic username="username" password="password" />

    https://learn.microsoft.com/en-us/azure/api-management/api-management-authentication-policies


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.