AAD B2C Custom Policies: Read HTTP x-api-key headers on REST API

Mikhail Delly 126 Reputation points
2022-12-27T11:06:24.44+00:00

Hi.

For securing requests from b2c policies to AF the "Secure code approach" is used.

(https://{AF endpoint}?code={secure code})

In this case AF has open API but could not be accessed without knowing this code.

I am trying to find similar approach for REST API:

<TechnicalProfile Id="REST-API">
<DisplayName>REST-API</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ServiceUrl">Url</Item>
<Item Key="SendClaimsIn">Body</Item>
<Item Key="AuthenticationType">ApiKeyHeader</Item>
</Metadata>
<CryptographicKeys>
<Key Id="x-functions-key" StorageReferenceId="B2C_1A_RestApiKey" /> (or x-api-key header)
</CryptographicKeys>

Is it possible to:

  1. Get x-functions-key or x-api-key from headers on Back-End side and get the code configured in Policy Keys using smth like:

if (!Request.Headers.TryGetValue("x-functions-key", out var extractedApiKey))
{
...
}

  1. Sending custom claims in body but B2C_1A_RestApiKey in header?
  2. If it doesn't work is this any working approach to send custom code from policy and read it on the Back-End side?

Thanks.

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,431 Reputation points Microsoft Employee Moderator
    2023-01-10T10:00:11.02+00:00

    Hi @Mikhail Delly ,

    Apologies for delay in response.

    Unfortunately, it is not possible to pass the code in policy keys or in the URL to read HTTP headers directly.

    I would suggest you post this idea at the Azure Feedback Portal, which is monitored by the product team for feature enhancements. Thank you for your time and patience throughout this issue.

    Thanks, Shweta


    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

Your answer

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