Implementing OAuth 2.0 with Software AG webMethods Integration Server
Tags: oauth2, integration, tutorial, authorization
Published: 2021-09-15 14:27:25

---
title: Implementing OAuth 2.0 with Software AG webMethods Integration Server
published: true
date: 2021-07-02 12:02:30 UTC
tags: #oauth2, #integration, #tutorial, #authorization
canonical_url: https://tech.forums.softwareag.com/t/implementing-oauth-2-0-with-webmethods-integration-server/242543
---

webMethods Integration Server supports OAuth 2.0. The Integration Server (IS) can be used as an OAuth client, an authorization server, or a resource server. This post describes how to use OAuth 2.0 with Integration Server.

Integration Server supports four types of OAuth grant types –

1. Authorization Code Grant  
2. Client Credentials Grant* 
3. Implicit Grant 
4. Resource Owner Password Credentials Grant

## Theoretical Knowledge

The **authorization code** grant type is used to authenticate and provide access to clients that are registered on the authorization server (Here our Integration Server is acting as an Authorization server as well).

This grant type requires the claiming client to authenticate to the authorization server before obtaining an access token and provides access to confidential and public clients.

When using the authorization code grant type, the authorization server can issue a **refresh token** to the registered client application along with the **access token**.  
A refresh token enables clients to get a new access token without requesting additional approval from the resource owner. When the access token expires, the client application can use the _pub.oauth:getToken_(replaced by now depreciated _getAccessToken_) service to pass the refresh token to the authorization server to request a new access token.

## Practical Knowledge

### Step 1 - Client Configuration:

A client must register himself and obtain client\_id from the integration server. In the IS console go to Security->OAuth->Client Registration page and click on ‘Register Client’. Enter the information as shown below. Redirect URL should be the URL, where IS will redirect the page after authorizing the request. I have created a simple RESTful service on the IS as a redirect URL.

**Remember that the Client ID will be generated when you click Save Changes.** Please note that in order to get the client secret generated for your client. Please select the type as ‘Confidential’ from the drop down menu.

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

**Your client will use this ‘Client ID’ to authorize himself and request an access token.**

### Step 2 - Scope Management:

The scope indicates the resources the client can access on behalf of resource owner. You need to indicate one or more folders or services on the IS in the scope. Once a client is granted access to a scope, he can access the folders and services included in that scope.

Go to Security->Oauth->Scope Management page and click on ‘Add Scope’. Once the page is open, mention the scope details as shown below

Here I have created a simple calculator API for demonstration purpose and included it’s

a. Fully qualified name of the calculator flow service.  
b. Resource path mapped to it in the REST descriptor service i.e. - **/oauth2/calculate**  
c. And the package name it is residing in(Optional, and to be done only if you want to include other services residing in the same package also to have the same scope).

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

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

Once the scope is added, map the scope with the client using the _Associate Scope to Clients_ nested option in the **Scope Management** option in **OAuth**.

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

Once this setup is done your client is ready to request for the access token to Authorization Server.

### Step 3 - Authorization Code Generation

Requesting token for authorization code approach is a 2-step process. In the first step, the client authorizes himself with the authorization server using _pub.oauth:authorize_ service and receives the authorization code. Once the authorization code is received, it can be used to obtain the access token using _pub.oauth:getToken_ service.

When the client initiates the _pub.oauth:authorize_ request, it brings up a page for the resource owner to either approve the access request or reject it.

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

Official Documentation Link - [OAuth Documentation](https://documentation.softwareag.com/webmethods/microservices_container/msc10-3/10-3_MSC_PIE_webhelp/index.html#page/integration-server-integrated-webhelp%2Fto-configure_oauth_2.html%23)

### Step 4 - Access Token

When the resource owner approves the request, the integration server generates the authorization code and redirects the page to the ‘redirect URL’ specified in the client configuration.

The service hosted at redirect URL passes the authorization code to _pub.oauth:getToken_ service to exchange authorization code for an access token as shown below.

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/8/68b9b171b302f3f04c08503571983a157549dcd4.png)

Integration Server administrator can verify all the tokens in the IS console.

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

The client application can use the token as a bearer token to access the resource on the server i.e. to run the calculator API in my case. ![:slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=9 ":slight\_smile:")

Homework for my audience - ![:slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=9 ":slight\_smile:")

1. How did I invoke getTokenService?
2. Can we skip the approval page to by default approve every incoming request?
3. How do we check whether our access token has been expired, explicitly? Is there more than one way?
4. Which service is invoked as a listener of that Approve button on the dynamic server page as depicted in the above screenshot?
5. Can that back-end service (mentioned in #4) be invoked normally or is there a specific way to invoke it?

Hint - Hints to all these questions are either in screenshots or the information mentioned above. I will answer these as well but would like you to try them first. ![:slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=9 ":slight\_smile:")

Comment below to let me know what did you think of this post & whether you require more such posts from me in the respected Tech community of Software AG. Also, do let me know if you need more information on other grant types and their respective implementation.

Thank you for being a patient audience!

[Read full topic](https://tech.forums.softwareag.com/t/implementing-oauth-2-0-with-webmethods-integration-server/242543)