-
-
optionchanged('auth_url', e.target.value)}
- value={auth_url}
- />
+
+
+
+
+
-
-
-
+ {grant_type === 'authorization_code' && (
+
+
+
+ optionchanged('auth_url', e.target.value)}
+ value={auth_url}
+ />
+
+
+
+
+
+
+
+
+
-
-
-
+ );
+ } else if (auth_type === 'basic') {
+ return (
+
+
+
+ optionchanged('username', e.target.value)}
+ value={username}
/>
- )}
-
- );
+
+
+
optionchanged('password', e.target.value)}
+ value={password}
+ />
+
+
+ );
+ } else if (auth_type === 'bearer') {
+ return (
+
+
+
+
optionchanged('bearer_token', e.target.value)}
+ value={bearer_token}
+ />
+
+
+ );
+ } else {
+ return null;
+ }
};
export default Authentication;
diff --git a/frontend/src/_ui/OAuth/index.js b/frontend/src/_ui/OAuth/index.js
index 4fafa04e9f..e4dc458812 100644
--- a/frontend/src/_ui/OAuth/index.js
+++ b/frontend/src/_ui/OAuth/index.js
@@ -12,6 +12,9 @@ const OAuth = ({
custom_auth_params,
custom_query_params,
scopes,
+ username,
+ password,
+ bearer_token,
auth_url,
header_prefix,
add_token_to,
@@ -22,6 +25,8 @@ const OAuth = ({
>
diff --git a/plugins/packages/restapi/lib/index.ts b/plugins/packages/restapi/lib/index.ts
index 99d41a7e9d..635810c198 100644
--- a/plugins/packages/restapi/lib/index.ts
+++ b/plugins/packages/restapi/lib/index.ts
@@ -2,7 +2,7 @@ const urrl = require('url');
import { readFileSync } from 'fs';
import * as tls from 'tls';
import { QueryError, QueryResult, QueryService } from '@tooljet-plugins/common';
-import got, { Headers, HTTPError } from 'got';
+import got, { Headers, HTTPError, OptionsOfTextResponseBody } from 'got';
function isEmpty(value: number | null | undefined | string) {
return (
@@ -79,7 +79,8 @@ export default class RestapiQueryService implements QueryService {
async run(sourceOptions: any, queryOptions: any, dataSourceId: string): Promise
{
/* REST API queries can be adhoc or associated with a REST API datasource */
const hasDataSource = dataSourceId !== undefined;
- const requiresOauth = sourceOptions['auth_type'] === 'oauth2';
+ const authType = sourceOptions['auth_type'];
+ const requiresOauth = authType === 'oauth2';
const headers = this.headers(sourceOptions, queryOptions, hasDataSource);
const customQueryParams = sanitizeCustomParams(sourceOptions['custom_query_params']);
@@ -119,17 +120,29 @@ export default class RestapiQueryService implements QueryService {
const method = queryOptions['method'];
const json = method !== 'get' ? this.body(sourceOptions, queryOptions, hasDataSource) : undefined;
const paramsFromUrl = urrl.parse(url, true).query;
+
+ if (authType === 'bearer') {
+ headers['Authorization'] = `Bearer ${sourceOptions.bearer_token}`;
+ }
+
+ const requestOptions: OptionsOfTextResponseBody = {
+ method,
+ headers,
+ ...this.fetchHttpsCertsForCustomCA(),
+ searchParams: {
+ ...paramsFromUrl,
+ ...this.searchParams(sourceOptions, queryOptions, hasDataSource),
+ },
+ json,
+ };
+
+ if (authType === 'basic') {
+ requestOptions.username = sourceOptions.username;
+ requestOptions.password = sourceOptions.password;
+ }
+
try {
- const response = await got(url, {
- method,
- headers,
- ...this.fetchHttpsCertsForCustomCA(),
- searchParams: {
- ...paramsFromUrl,
- ...this.searchParams(sourceOptions, queryOptions, hasDataSource),
- },
- json,
- });
+ const response = await got(url, requestOptions);
result = this.isJson(response.body) ? JSON.parse(response.body) : response.body;
requestObject = {
requestUrl: response.request.requestUrl,
diff --git a/plugins/packages/restapi/lib/manifest.json b/plugins/packages/restapi/lib/manifest.json
index 030cb7e6be..bbae720879 100644
--- a/plugins/packages/restapi/lib/manifest.json
+++ b/plugins/packages/restapi/lib/manifest.json
@@ -32,6 +32,12 @@
"type": "string",
"encrypted": true
},
+ "password": {
+ "encrypted": true
+ },
+ "bearer_token":{
+ "encrypted": true
+ },
"scopes": {
"type": "string"
},
@@ -83,6 +89,15 @@
"scopes": {
"value": "read, write"
},
+ "username": {
+ "value": ""
+ },
+ "password": {
+ "value": ""
+ },
+ "bearer_token": {
+ "value": ""
+ },
"auth_url": {
"value": ""
},