PhilipSkinner / elemental-lowcode

Elemental lowcode development platform.
MIT License
113 stars 17 forks source link

Integrations - query token - OAuth client credentials #125

Open PhilipSkinner opened 2 years ago

PhilipSkinner commented 2 years ago

Add support for client credentials bearer token authentication on outgoing HTTP requests.

The configuration for this authentication mechanism should be:

{
  "request": {
    "uri": "https://jsonplaceholder.typicode.com/posts/$.body.id",
    "method": "get",
    "authentication" : {
      "mechanism" : "client_credentials",
      "type" : "query",
      "config" : {
        "client" : "my-client",
        "scopes" : [
          "scope_1",
          "scope_2"
        ],
        "param" : "query_param_name"
      }
    }
  }
}

The client value references an oauth provider. The scopes are an optional set of scopes which override the default scopes setup within the oauth provider.

Create a refreshing token store that can always return a valid token into the requestService. As we do not know the structure of the token, and we may not be able to inspect it to determine its expiration, the token store should assume that it is not possible to glean this information from the token. Instead it should provide a mechanism for handling 401 responses from the requestService.sendRequest method, which will refresh the token. This must not cause an infinite loop and should only be retried once.

When this authentication mechanism is present the requestService within the integration application should add a query parameter onto the URI being requested:

GET https://my.service/api/v1/users?<param>=<token>