0
votes

I try to modify the backend of our api management from resource to a webapp api. I have taken Use Azure Api Management as a passthrough as a reference.

the exposed api is: https://service-api-management.azure-api.net/api-name/operation-name

the actual api I want to call is: https://service-name.azurewebsites.net/api/Skills/Async/operation-name

apart from the uri, the request body and header should remain the same. So I have the below policy set up to change the uri. But the response is a html showing redirect.

Curiously about why it returns a html showing redirecting and how can I make the redirect work properly. Any input would be appreciated.

Policy:

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="https://service-name.azurewebsites.net" />
        <rewrite-uri template="@(context.Request.Url.Path.Replace("/operation-name","/api/Skills/Async/operation-name"))" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Response:

<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
    <head>
        <title>Redirecting</title>
      ......
1
Update: Finally figured out that there is a policy in the API level that remove the Authorization token in header so when backend forward the request there is no token and that's why it get redirected to the log in page.RZzz G

1 Answers

1
votes

Test and see what your backend service returns to a tool like Postman or Fiddler, those would be best to emulate regular HTTP request not sent by browser. Perhaps backend expects some header in request that is sent implicitly, or maybe redirect is just very fast and not noticeable by user. To make it work through APIM you'll hve to take care to either not trigger redirect or make it redirect to APIM again. To some extent redirect-content-urls policy may be of use here: https://docs.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#MaskURLSContent