Authenticating webMethods.io API Gateway APIs using OKTA as authorization server for OpenID mechanism
Tags: okta, api, openid, tutorial
Published: 2021-07-29 09:11:06

---
title: Authenticating webMethods.io API Gateway APIs using OKTA as authorization server for OpenID mechanism
published: true
date: 2021-07-14 14:35:49 UTC
tags: #okta, #api, #openid, #tutorial
canonical_url: https://tech.forums.softwareag.com/t/authenticating-webmethods-io-api-gateway-apis-using-okta-as-authorization-server-for-openid-mechanism/242826
---

### Introduction

This article explains about how to implement OpenID on API gateway for OKTA authorization server

### Audience

It is assumed that readers of this article know how to setup API’s in API gateway.

### Pre-Requisites

• Active tenant subscription on [Webmethods.io](http://Webmethods.io) API Gateway  
• Configure the API in API gateway.  
• Create Application and associate API with 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)

• Active account for OKTA

### Use Case:

• We configured the API in API Gateway. This API checks the availability of bed in hospitals.  
• To invoke this API from API Gateway we have implemented the OpenID connect mechanism.  
• In our case, OKTA will be working as authorization server.

### What is OpenID?

• OpenID Connect (OIDC) is a thin layer that sits on top of OAuth 2.0 that adds login and profile information about the person who is logged in.

• Establishing a login session is often referred to as authentication, and information about the person logged in (i.e. the Resource Owner) is called identity.

• When an Authorization Server supports OIDC, it is sometimes called an identity provider, since it provides information about the Resource Owner back to the Client.

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

### Grant Types

```
 OpenID Connect supports the following authentication flows

```

• The Implicit Flow is required for apps that have no “back end” logic on the web server, like a Javascript app.

• The Authentication (or Basic) Flow is designed for apps that have a back end that can communicate with the IdP away from prying eyes.  
• The Resource Owner Password Grant does not have an login UI and is useful when access to a web browser is not possible.

• The Client Credentials Grant is useful for machine to machine authorization.

For More info please follow below link:  
[An Illustrated Guide to OAuth and OpenID Connect | Okta Developer](https://developer.okta.com/blog/2019/10/21/illustrated-guide-to-oauth-and-oidc)

### Configuration at OKTA (Authorization server)

### Create Application

• Login to Okta Account  
• Navigate to application, click on create New Application  
• Select API services  
• Click Next and Save it.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/b/c/bc717583a9e6eb9685c911de2917dfcc32526f79.png)

• Copy the Client ID and client secret  
• Save the credentials for future use.

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

### Create Authorization server

• Navigate to Security and then select API  
• Select Add in Authorization server.

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

• Create rule with default settings

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/7/4/748f5f96ae3bb957e20050ae463b9f3535b5f82f.png)

### Create Token

• Navigate to the security and then select API  
• Click on create token  
• Name the token as okta token  
• Copy the token and save it for future use.  
• This token will be configured in API GW as SSWS token.

### API Used for our Use case at [webmethods.io](http://webmethods.io) API Gateway

```
   **API Name:** CheckBedAvailability

```

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

### Enforce policy

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


![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/b/a/ba475ec758570a68b004dc3e7654767ea0c2718c.png)

• Select Identify & Authorize Application.  
• Select OpenID connect.  
• Save the changes.

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

### Create Scope in API

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

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

Before Configuring the Authorization server, we need to understand couple of terminologies

### Introspection :

Introspection is the way to authenticate the token. It is sub divided into 2 parts

1. **Local introspection**  
Validating the token within the gateway. This can be done using the JWKS URI or the public certificate of the issuer. For this the token should necessarily be JWT.
2. **Remote introspection** : Validating the token with the authorization server. It has introspection endpoint, which is used to validate the token. Along with that we have client id and client secret which we are used to protect the endpoint, so that anonymous users won’t get access to the resource. Underneath to invoke an endpoint we need a user, Gateway user is the one under which we invoke the endpoint.  
Dynamic client registration  
Dynamic client registration is used when you want to create the client automatically in the OAuth2 authorization server when application is created in API Gateway.

**Add Authorization Server**

• Click on administration tab  
• Navigate to Security tab  
• From the left-hand tab click on JWT\OAuth\OpenID  
• Click on Add authorization server.  
• Provide the name as ExternalOktaServer

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

1. Provide the Discovery URL and click on Discover.
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/3/a3c1818aef2e7659765a2cb6085e18bcf4bdf9db.png)
2. This will populate the values on Introspection, Dynamic client registration and in Metadata.
3. Add the scope and save it.
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/e/7/e7ea25d8131773e5a964e04dd549af2b4710441e.png)

### Map Scope OAuth Scopes

1. Click on map Scope
2. Give the authorization server scope , In our case it will be OktaAuthServerScopeMapping
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/4/8/488c5d07fbf344c4dcf5fb19076b0bae6e75370a.png)
3. Give the API scope name In our case it we have given in CheckBedAvailibiltyScopeV3
4. Click Save.
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/5/3/53e1be2a8da1c0c0ee0357bc1d57a7e89457fd5b.png)

### Create Application

1. Click on create Application and name it as OpenIDApp.
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 OpenID
5. Provide the name for the strategy, In our case we have named it as OktaStrategy
6. Select the authentication server as OktaAuthServer.
7. Provide ClientID
8. Enable the HMAC Algorithm.
9. Provide the client secret
10. Click Save

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/7/5/75d681aeafd2a8585b5e7f7fc4f032b39159803b.png)

### Test Using postman client

1. Select Authorization as OAuth 2.0
2. Set the below values
**Grant Type** : Authorization code  
**Call Back url** : [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback)  
**Authorise URL** : We can get the from the metadata provided by OKTA  
**Access Token URL** : We can get the from the metadata provided by OKTA  
**Client ID** : We can get the from the metadata provided by OKTA  
**Client Secret** : We can get the from the metadata provided by OKTA  
**Scope** : openid  
**State** : Any random alphanumeric value  
**Client Authentication** : Send Client credentials in Body
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/5/65a958779e745f7de12c17021fafd7bceb74e73a.png)
3. Click on generate token
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/7/4/7492fa37adeda191c03da1a56a4ae65877866225.png)
4. Click on use token
5. Submit the request
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/d/6d308f7d9b1059790482764b61a95c8f32e6f21c.png)
6. Validate the response.

[Read full topic](https://tech.forums.softwareag.com/t/authenticating-webmethods-io-api-gateway-apis-using-okta-as-authorization-server-for-openid-mechanism/242826)