Securing an API using OAuth 2.0 in Azure API Management part-3 | CloudFronts

Securing an API using OAuth 2.0 in Azure API Management part-3

Posted On December 4, 2020 by Shrusti Talati Posted in

Part 3: OAUTH 2.0 Server setup


Configuring OAuth 2.0 for your APIs hosted in Azure API Management adds an extra layer of security and prevents unauthorized access. This is a very important configuration form Security point of view for your Endpoints and is provided out of the box by Azure. This is the second part of a series of Blogs on Securing your API using OAuth 2.0 in Azure API Management. Please go through all the parts to find easy and detailed steps that will help you configure the OAuth 2.0 Authentication.

Enable OAuth 2.0 user authorization in the Developer Console

At this point, you have created your applications in Azure AD, and have granted proper permissions to allow the client-app to call the backend-app.

In this example, the Developer Console is the client-app. The following steps describe how to enable OAuth 2.0 user authorization in the Developer Console.

  1. In Azure portal, browse to your API Management instance.
  2. Select OAuth 2.0 > Add.
  1. Provide a Display name and Description.
  2. For the Client registration page URL, enter a placeholder value, such as http://localhost. The Client registration page URL points to a page that users can use to create and configure their own accounts for OAuth 2.0 providers that support this. In this example, users do not create and configure their own accounts, so you use a placeholder instead.
  3. For Authorization grant types, select Authorization code.
  1. Specify the Authorization endpoint URL and Token endpoint URL. Retrieve these values from the Endpoints page in your Azure AD tenant. Browse to the App registrations page again and select Endpoints.
  2. Copy the OAuth 2.0 Authorization Endpoint, and paste it into the Authorization endpoint URL text box. Select POST under Authorization request method.
  3. Copy the OAuth 2.0 Token Endpoint, and paste it into the Token endpoint URL text box.


You can use either v1 or v2 endpoints. However, depending on which version you choose, the below step will be different. We recommend using v2 endpoints.

  1. If you use v1 endpoints, add a body parameter named resource. For the value of this parameter, use Application ID of the back-end app.
  2. If you use v2 endpoints, use the scope you created for the backend-app in the Default scope field. Also, make sure to set the value for the accessTokenAcceptedVersion property to 2 in your application manifest.
  3. Next, specify the client credentials. These are the credentials for the client-app.
  4. For Client ID, use the Application ID of the client-app.
  5. For Client secret, use the key you created for the client-app earlier.
  1. Immediately following the client secret is the redirect_url for the authorization code grant type. Make a note of this URL.
  2. Select Create.

Go back to your client-app registration in Azure Active Directory and select Authentication.

Under Platform configurations click on Add a platform, and select the type as Web, paste the redirect_url under Redirect URI, and then click on Configure button to save.

Now that you have configured an OAuth 2.0 authorization server, the Developer Console can obtain access tokens from Azure AD.

Enable OAuth 2.0 user authorization for your API.

This enables the Developer Console to know that it needs to obtain an access token on behalf of the user, before making calls to your API.

  1. Browse to your API Management instance and go to APIs.
  2. Select the API you want to protect. For example, you can use the Echo API.
  3. Go to Settings.
  1. Under Security, choose OAuth 2.0, and select the OAuth 2.0 server you configured earlier.
  2. Select Save.

Share Story :

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.