Skip to content

Commit 97cda3c

Browse files
authored
➕ ADDS: none authentication type (#206)
This pull request introduces a new authentication type, none, to the HTTP data source configuration.
1 parent 3ad5c50 commit 97cda3c

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

inc/Integrations/GenericHttp/GenericHttpDataSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GenericHttpDataSource extends HttpDataSource {
2424
'properties' => [
2525
'type' => [
2626
'type' => 'string',
27-
'enum' => [ 'basic', 'bearer', 'api-key' ],
27+
'enum' => [ 'basic', 'bearer', 'api-key', 'none' ],
2828
],
2929
'value' => [
3030
'type' => 'string',

src/data-sources/components/HttpAuthSettingsInput.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,21 @@ export const HttpAuthSettingsInput: React.FC< HttpAuthSettingsInputProps > = ( {
7474
</>
7575
) }
7676

77-
<div className="form-group">
78-
<PasswordInputControl
79-
id="authValue"
80-
label={ __( 'Authentication Value', 'remote-data-blocks' ) }
81-
value={ auth.authValue }
82-
onChange={ value => onChange( 'authValue', value ) }
83-
__next40pxDefaultSize
84-
help={ __(
85-
'The authentication value to use for the HTTP endpoint. When using Basic Auth, this is "username:password" string.',
86-
'remote-data-blocks'
87-
) }
88-
/>
89-
</div>
77+
{ auth.authType !== 'none' && (
78+
<div className="form-group">
79+
<PasswordInputControl
80+
id="authValue"
81+
label={ __( 'Authentication Value', 'remote-data-blocks' ) }
82+
value={ auth.authValue }
83+
onChange={ value => onChange( 'authValue', value ) }
84+
__next40pxDefaultSize
85+
help={ __(
86+
'The authentication value to use for the HTTP endpoint. When using Basic Auth, this is "username:password" string.',
87+
'remote-data-blocks'
88+
) }
89+
/>
90+
</div>
91+
) }
9092
</>
9193
);
9294
};

src/data-sources/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const GOOGLE_SHEETS_API_SCOPES = [
3232
/**
3333
* REST API Source Constants
3434
*/
35-
export const AUTH_TYPES = [ 'bearer', 'basic', 'api-key' ] as const;
35+
export const AUTH_TYPES = [ 'bearer', 'basic', 'api-key', 'none' ] as const;
3636
export const API_KEY_ADD_TO = [ 'queryparams', 'header' ] as const;
3737

3838
/**
@@ -44,6 +44,7 @@ export const HTTP_SOURCE_AUTH_TYPE_SELECT_OPTIONS: SelectOption<
4444
{ label: __( 'Bearer', 'remote-data-blocks' ), value: 'bearer' },
4545
{ label: __( 'Basic', 'remote-data-blocks' ), value: 'basic' },
4646
{ label: __( 'API Key', 'remote-data-blocks' ), value: 'api-key' },
47+
{ label: __( 'None', 'remote-data-blocks' ), value: 'none' },
4748
];
4849
export const HTTP_SOURCE_ADD_TO_SELECT_OPTIONS: SelectOption<
4950
( typeof API_KEY_ADD_TO )[ number ]

src/data-sources/http/HttpSettings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export const HttpSettings = ( {
8080
}
8181
}
8282

83+
if ( state.authType === 'none' ) {
84+
return state.slug && state.url;
85+
}
86+
8387
return state.slug && state.url && state.authType && state.authValue;
8488
}, [ state.slug, state.url, state.authType, state.authValue, state.authKey, state.authAddTo ] );
8589

src/data-sources/http/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ export interface HttpBasicAuth extends BaseHttpAuth {
1414
type: 'basic';
1515
}
1616

17-
export type HttpAuth = HttpBearerAuth | HttpBasicAuth | HttpApiKeyAuth;
17+
export type HttpAuth = HttpBearerAuth | HttpBasicAuth | HttpApiKeyAuth | HttpNoAuth;
1818

1919
export interface HttpApiKeyAuth extends BaseHttpAuth {
2020
type: 'api-key';
2121
key: string;
2222
addTo: ( typeof API_KEY_ADD_TO )[ number ];
2323
}
2424

25+
export interface HttpNoAuth extends BaseHttpAuth {
26+
type: 'none';
27+
}
28+
2529
export type HttpAuthFormState = {
2630
authType: ( typeof AUTH_TYPES )[ number ];
2731
authValue: string;

0 commit comments

Comments
 (0)