Skip to content

Commit

Permalink
➕ ADDS: none authentication type (#206)
Browse files Browse the repository at this point in the history
This pull request introduces a new authentication type, none, to the HTTP data source configuration.
  • Loading branch information
mehmoodak authored Nov 22, 2024
1 parent 3ad5c50 commit 97cda3c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion inc/Integrations/GenericHttp/GenericHttpDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GenericHttpDataSource extends HttpDataSource {
'properties' => [
'type' => [
'type' => 'string',
'enum' => [ 'basic', 'bearer', 'api-key' ],
'enum' => [ 'basic', 'bearer', 'api-key', 'none' ],
],
'value' => [
'type' => 'string',
Expand Down
28 changes: 15 additions & 13 deletions src/data-sources/components/HttpAuthSettingsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ export const HttpAuthSettingsInput: React.FC< HttpAuthSettingsInputProps > = ( {
</>
) }

<div className="form-group">
<PasswordInputControl
id="authValue"
label={ __( 'Authentication Value', 'remote-data-blocks' ) }
value={ auth.authValue }
onChange={ value => onChange( 'authValue', value ) }
__next40pxDefaultSize
help={ __(
'The authentication value to use for the HTTP endpoint. When using Basic Auth, this is "username:password" string.',
'remote-data-blocks'
) }
/>
</div>
{ auth.authType !== 'none' && (
<div className="form-group">
<PasswordInputControl
id="authValue"
label={ __( 'Authentication Value', 'remote-data-blocks' ) }
value={ auth.authValue }
onChange={ value => onChange( 'authValue', value ) }
__next40pxDefaultSize
help={ __(
'The authentication value to use for the HTTP endpoint. When using Basic Auth, this is "username:password" string.',
'remote-data-blocks'
) }
/>
</div>
) }
</>
);
};
3 changes: 2 additions & 1 deletion src/data-sources/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const GOOGLE_SHEETS_API_SCOPES = [
/**
* REST API Source Constants
*/
export const AUTH_TYPES = [ 'bearer', 'basic', 'api-key' ] as const;
export const AUTH_TYPES = [ 'bearer', 'basic', 'api-key', 'none' ] as const;
export const API_KEY_ADD_TO = [ 'queryparams', 'header' ] as const;

/**
Expand All @@ -44,6 +44,7 @@ export const HTTP_SOURCE_AUTH_TYPE_SELECT_OPTIONS: SelectOption<
{ label: __( 'Bearer', 'remote-data-blocks' ), value: 'bearer' },
{ label: __( 'Basic', 'remote-data-blocks' ), value: 'basic' },
{ label: __( 'API Key', 'remote-data-blocks' ), value: 'api-key' },
{ label: __( 'None', 'remote-data-blocks' ), value: 'none' },
];
export const HTTP_SOURCE_ADD_TO_SELECT_OPTIONS: SelectOption<
( typeof API_KEY_ADD_TO )[ number ]
Expand Down
4 changes: 4 additions & 0 deletions src/data-sources/http/HttpSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const HttpSettings = ( {
}
}

if ( state.authType === 'none' ) {
return state.slug && state.url;
}

return state.slug && state.url && state.authType && state.authValue;
}, [ state.slug, state.url, state.authType, state.authValue, state.authKey, state.authAddTo ] );

Expand Down
6 changes: 5 additions & 1 deletion src/data-sources/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ export interface HttpBasicAuth extends BaseHttpAuth {
type: 'basic';
}

export type HttpAuth = HttpBearerAuth | HttpBasicAuth | HttpApiKeyAuth;
export type HttpAuth = HttpBearerAuth | HttpBasicAuth | HttpApiKeyAuth | HttpNoAuth;

export interface HttpApiKeyAuth extends BaseHttpAuth {
type: 'api-key';
key: string;
addTo: ( typeof API_KEY_ADD_TO )[ number ];
}

export interface HttpNoAuth extends BaseHttpAuth {
type: 'none';
}

export type HttpAuthFormState = {
authType: ( typeof AUTH_TYPES )[ number ];
authValue: string;
Expand Down

0 comments on commit 97cda3c

Please sign in to comment.