Authenticating webMethods.io API Gateway APIs using OAuth2.0 using local authorization server
Tags: oauth2, api, authentication, tutorial
Published: 2021-10-18 14:44:13

---
title: Authenticating webMethods.io API Gateway APIs using OAuth2.0 using local authorization server
published: true
date: 2021-05-31 06:06:09 UTC
tags: #oauth2, #api, #authentication, #tutorial
canonical_url: https://tech.forums.softwareag.com/t/authenticating-webmethods-io-api-gateway-apis-using-oauth2-0-using-local-authorization-server/241764/1
---

## Introduction

This article explains about how to implement OAuth 2.0 on API Gateway for local authorization server

### Audience

It is assumed that readers of this article know how to set up API’s and policies on API Gateway.

### Prerequisites

• Active tenant subscription on [webMethods.io](http://webMethods.io) API Gateway  
• Configure the API at API gateway.  
• Create Application and associate API with the application.  
• Refer the link to create API  
[GitHub - SoftwareAG/webmethods-api-gateway: Repository hosting developer tutorials, code samples, custom policies, CI/CD scripts and more to enable developers develop faster with API Gateway](https://github.com/SoftwareAG/webmethods-api-gateway)

## Use Case:

• We configured the API on API Gateway. This API checks the availability of beds in hospitals.  
• To invoke this API from API Gateway we have implemented the OAuth 2.0 mechanism.  
• In our case our API Gateway will be working as an authorization server.  
• First we will get the access token from the authorization server and then the same token will be passed to access the API.

### What is OAuth 2.0?

OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices.

For detailed information follow the below link: [OAuth 2.0 — OAuth](https://oauth.net/2/)

### How OAuth 2.0 works?

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/1/7/176fc29a40e1a769323a1ce04d502a55d2cc4a6f.png)

### API Used for our Use case:

```
   **API Name:** CheckBedAvailability

```

[![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/9/4/94cb6cc5873ba37c2cab3187d3a236fa8b5b1d6c_2_690x120.png)](https://aws1.discourse-cdn.com/techcommunity/original/3X/9/4/94cb6cc5873ba37c2cab3187d3a236fa8b5b1d6c.png "image")

### Enforce policy

- Open the API CheckBedAvailability.
- Navigate to the policy
- Click on Identify & Access policy.

![image](https://aws1.discourse-cdn.com/techcommunity/original/2X/9/9ee269f4e5113f3e652389c333bafd8c04e1621a.png)

- Select Identify & Authorize Application.
- Select OAuth2 Token.
- Save the changes.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/e/2/e26da278eebbd4caa15eac3f9120e2f9356ba10c.png)

### Create Scope in API

1. Go to the API in our case it is checkBedAvailablity
2. Navigate to scopes within the API
3. Create the scope and map the resource with it
4. In our case scope name is CheckBedAvailibiltyScope
5. Add resource name is CheckBedAvailability
6. Click Save.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/4/640fc5c94abb21d783efeae6b941ed830dc5a5f1.png)

Add Scope to Auth Server

1. Click on the administration tab
2. Navigate to the Security tab
3. From the lefthand tab click on JWT\OAuth\OpenID
4. Click on the local authorization server
5. Add the scope and save it.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/e/d/ed3ad85345e091ac0e81bb9b72cd4e77e06a80eb.png)

### Map Scope OAuth Scopes

1. Click on map Scope
2. Give the authorization server scope, In our case, it will be local:OAuthCheckBedAvailabilityScope
3. Give the API scope name In our case it will behave given in CheckBedAvailibiltyScope
4. Click Save

### Create Application

1. Click on create Application and name it as HospitalManagmentApplication.
2. Select the API which we want to associate with this application. In our case it will checkBedAvailibility API.
3. Click on Authentication and then click on Create Strategy
4. Select Authentication scheme as OAuth2
5. Provide the name for the strategy
6. Select the authentication server as local.
7. Enable the generate the credentials
8. Select application type as Confidential
9. Application profile as web
10. Select Grant Type as “Client\_credentials”
11. Select the scope in our case it will be OAuthCheckBedAvailabilityScope
12. Click on Add.
13. It will generate the client ID and client credentials, which will be used to generate the access token.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/1/3/133b00ac338580845f8b7b9c12d2b80fa202cd46.png)

### Test Using postman client

1. Select Authorization as OAuth 2.0
2. Set the below values
Access Token: https://.gateway.webmethodscloud.com/invoke/pub.apigateway.oauth2/getAccessToken  
Grant Type: Client Credentials  
Client ID: Available in the application  
Client Secret: Available in the application  
Client Authentication: Send As Basic Auth header
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/1/d/1da8f40347315275642e6055381f58871fe4684f.png)
2. Click on generate token
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/3/a36318eabd9e60e970f19b96b9921fc63124d9c1.png)
3. Click on use token
4. Submit the request
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/d/6d308f7d9b1059790482764b61a95c8f32e6f21c.png)
5. Validate the response.

[Read full topic](https://tech.forums.softwareag.com/t/authenticating-webmethods-io-api-gateway-apis-using-oauth2-0-using-local-authorization-server/241764/1)