OAuth and Custom Auth using CLI
Tags: webmethods, integration, connector, connectorbuilder
Published: 2021-12-15 12:09:49

---
title: OAuth and Custom Auth using CLI
published: true
date: 2021-12-02 14:31:23 UTC
tags: webmethods, integration, connector, connectorbuilder
canonical_url: https://tech.forums.softwareag.com/t/oauth-and-custom-auth-using-cli/253657
---

OAuth is a token-based authentication method that allows the user’s account information to be used by any external service and subsequently provide secure access, without exposing the password. For example, many websites support multiple login methods. One of the login methods you commonly see is logging in through Gmail or logging in through Facebook. This is an example of OAuth. Given below is the basic structure for the OAuth authentication.

[webMethods.io](http://webMethods.io) Integration’s CLI framework provides built-in OAuth authentication modules for a number of services. You can either use these built-in modules or create custom OAuth authentication modules as per your requirements.

There are two ways to create OAuth authentications:

1. Using built-in OAuth authentication modules provided by [webMethods.io](http://webMethods.io)
2. Creating custom OAuth authentication modules

To use these built-in OAuth authentication modules to create authentications, follow the steps given below:  
Using built-in OAuth authentication modules provided by [webMethods.io](http://webMethods.io)

**Using built-in OAuth authentication modules provided by [webMethods.io](http://webMethods.io)**

**Step 1.** : Execute ‘wmio auth’ command in connector builder, and select . **‘oauth > built-in’.** option. You can see the list of services for which [webMethods.io](http://webMethods.io) provides built-in OAuth authentication modules

**![](https://aws1.discourse-cdn.com/techcommunity/original/3X/1/6/16645df4516622a47d8260ed37711fd72e06da46.png)**

**Step 2:** Select the service for which you want to create OAuth authentication.

This will create an **‘authentication.js’** file in your app directory, in which you can add your authentication logic. The basic OAuth authentication structure is given below:

OAuth authentication structure

```
module.exports = {
  label : 'Connect to Gmail,    
  mock_input: 
   { 
     access_token: 'token' 
   }, 
  oauth: 'gmail',
  input: {},
  validate : function (input, output)
  {
    // auth data will be available in input.auth
    // var accessToken = input.auth.access_token;
  }
}

```

Let’s understand more about this structure with the help of an example.

### Example
To check the example on using built-in OAuth authentication modules provided by webMethods.io, visit the original post in the [Software AG Tech Community](https://tech.forums.softwareag.com/t/oauth-and-custom-auth-using-cli/253657). 

### 2. Creating custom OAuth authentication modules

[webMethods.io](http://webMethods.io) allows you to create custom OAuth authentication modules for any external service. To do this, follow the steps given below:

**Step 1:** Execute the wmio auth’ command in Connector Builder, and select ‘oauth > create new’ option

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

**Step 2:** You can see two options: ‘OAuth 1’ and ‘OAuth 2’. Select the OAuth type for which you want to create an authentication.

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

**Step 3:** Provide a name for your custom OAuth authentication module.

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

Once you have provided these details, a file named ‘ **oauth.json** ’ will be created in your app directory. You can then populate relevant values for the keys present in this file.

**Note:** You don’t need to make any modifications to the ‘authentication.js’ file for custom OAuth authentications.

The structure for the ‘ **OAuth1** ’ authentication module is given below:

```
{
 "type": "oauth1",
 "title": "{{title}}",
 "consumerKey": "<CONSUMER KEY>",
 "consumerSecret": "<CONSUMER SECRET>",
 "signatureMethod": "HMAC-SHA1",
 "requestURL": "<REQUEST URL>",
 "authURL": "<AUTH URL>",
 "accessURL": "<ACCESS TOKEN URL>",
 "requiredFields": [], 
 "authQueryParams": { },
 "validate": {
   "url": "ANY API URL TO VALIDATE TOKEN OF THIRD PARTY SERVICE",
   "headers": {
     //<optional>
   },
   "query": {
     //<optional>
     "oauth_token": "{oauth_token}",
     "oauth_token_secret": "{oauth_token_secret}"
   }
 },
 "redirectURL": "{{redirectURL}}"
}

```

Understand more about this structure with the help of another two examples found the original article in the [Software AG Tech Community](https://tech.forums.softwareag.com/t/oauth-and-custom-auth-using-cli/253657). 

#### Deploying the custom OAuth

Once you have created a custom OAuth, you need to deploy it on Connector Builder in order to start using it in your triggers and actions.

To deploy your custom OAuth, execute the **‘flow oauth deploy’** command in Connector Builder.

[![](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/7/c/7c4c16cc916bf27808876d14b74b09519469b764_2_624x95.png)](https://aws1.discourse-cdn.com/techcommunity/original/3X/7/c/7c4c16cc916bf27808876d14b74b09519469b764.png)
  
This will add your custom OAuth in the ‘Authorization’ fields of all Github actions and triggers.

```
{
  "type": "oauth2",
  "title": "github",
  "clientId": "81vqd1s4y***",
  "clientSecret": "cqL4JnnxHpcE**",
  "authURL": "https://github.com/login/oauth/authorization",
  "tokenURL": "https://github.com/login/oauth/access_token",
  "preAuthProcessing": {
    "Authorization": "Basic base64({client_id}{client_secret})"
  },
  "authQueryParams": {
    "client_id": "{client_id}",
    "client_secret": "{client_secret}"
  },
  "preTokenProcessing": {
    "headers": {
      "Authorization": "Basic base64({client_id}{client_secret})"
    }
  },
  "tokenParams": {
    "method": "",
    "headers": {},
    "data": {
      "client_id": "{client_id}",
      "client_secret": "{client_secret}",
      "redirect_uri": "{redirect_uri}",
      "grant_type": "authorization_code"
    }
  },
  "preRefreshProcessing": {
    "Authorization": "Basic base64({client_id}{client_secret})"
  },
  "refreshParams": {
    "data": {
      "client_id": "{client_id}",
      "client_secret": "{client_secret}",
      "redirect_uri": "{redirect_uri}",
      "grant_type": "refresh_token",
      "refresh_token": "{refresh_token}"
    }
  },
  "requiredParams": [
    {
      "id": "domain",
      "title": "Domain",
      "description": "domain"
    }
  ],
  "includeParams": {
    "domain_url": "https://{domain}.example.com",
    "domain": "{domain}"
  },
  "refreshURL": "https://github.com/login/oauth/access_oken",
  "scope": {
    "public_repo": "Read/write access to public repos and organizations.",
    "gist": "Write access to gists."
  },
  "validate": {
    "url": "https://api.github.com/users/octocat/orgs",
    "headers": {
      "Authorization": "Bearer {access_token}"
    },
    "query": {}
  },
  "redirectURL": "https://auth-int.webmethods.io/auth/oauth/github_eb2804f6a2/fla8f8919884231f3a77973d/return"
}

```

**Custom OAuth**

To Enable custom authentication in your CLI Connector you need to create OAuth 2 and then add the following keys in your authentication.js file

“is\_default”: true  
“is\_custom”: true  
“custom\_oauth\_schema”:{}

**Is\_default** : Set to false if you want to disable default authorization  
**is\_custom** : Set to false if you want to disable Custom authorization  
**custom\_oauth\_schema** : Type of OAuth being used

Updating the Custom OAuth  
In case you want to make any changes in the custom OAuth of any service, you need to update the relevant details in the ‘oauth.json’ file for that custom OAuth and redeploy it using the **‘flow oauth deploy’** command in the Connector Builder.


[Read full topic](https://tech.forums.softwareag.com/t/oauth-and-custom-auth-using-cli/253657)