Secure ways to obtain and pass subscription key through APIM using SPA hosted in Storage Account

hampton123 1,180 Reputation points
2023-12-20T20:09:38.42+00:00

Currently I have a self-hosted developer portal in my Azure Storage account. Users sign in via B2C, and then they are able to access whichever APIs are presented on the page that correlate to their input subscription key. Right now, this subscription key is located as a query parameter in the developer portal's URL (hosted by the SPA in Storage Account).

I don't want the URL to contain the subscription key because if the key was publicly shown to users and it is not rotated, then outside users could just sign up through the developer portal, sign in through B2C, and potentially access APIs they should not have access to. What is a secure way to obtain the subscription key associated with the B2C user, and provide that in API requests?

I was thinking that a more secure way to provide the subscription key is to make the API Management Service check the user's B2C token. Then, based on the B2C token, the subscription key associated with the B2C user would be provided through the request headers. For example, a SQL database with each row representing a user would have a column including their subscription key. The B2C token's object id would be prepared with each entry, and then when the user's object id matches a row, the subscription key associated with the B2C token would be passed back to the SPA.

Thank you for your help in advance, and please let me know if anything needs clarification.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
Microsoft Security | Microsoft Entra | Microsoft Entra External ID
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. MuthuKumaranMurugaachari-MSFT 22,446 Reputation points Moderator
    2023-12-21T15:21:56.12+00:00

    hampton123 Thanks for posting your question in Microsoft Q&A. I assume you have followed doc: Authenticate with Azure AD B2C for users to sign up/sign in via B2C and then access APIs. You are looking to secure the way to obtain subscription keys. Correct?

    You can configure Products in APIM to require approval and users would need to submit a subscription request in the developer portal. Only after the approval of subscription request by admin, users can get subscription keys and access APIs in the product.

    Source: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-add-products?tabs=azure-portal#create-and-publish-a-productUser's image

    With the above approach, still any B2C users can sign up in the developer portal but don't have access to Product's APIs. If you are in need to restrict such sign up, consider implementing delegation endpoint as described in doc: Delegating developer sign-in and sign-up. This provides more flexibility in adding your custom logic in that endpoint and applies for product subscription as well.

    I hope this helps and let me know if any questions.


    If you found the answer to your question helpful, please take a moment to mark it as Yes for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.


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.