import PropTypes from 'prop-types'; import React, { Component } from 'react'; import FieldSet from 'Components/FieldSet'; import FormGroup from 'Components/Form/FormGroup'; import FormInputButton from 'Components/Form/FormInputButton'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormLabel from 'Components/Form/FormLabel'; import OAuthInputConnector from 'Components/Form/OAuthInputConnector'; import Icon from 'Components/Icon'; import ClipboardButton from 'Components/Link/ClipboardButton'; import ConfirmModal from 'Components/Modal/ConfirmModal'; import { icons, inputTypes, kinds } from 'Helpers/Props'; import translate from 'Utilities/String/translate'; export const authenticationMethodOptions = [ { key: 'none', get value() { return translate('None'); }, isDisabled: true }, { key: 'external', get value() { return translate('External'); }, isHidden: true }, { key: 'basic', get value() { return translate('AuthBasic'); } }, { key: 'forms', get value() { return translate('AuthForm'); } }, { key: 'plex', get value() { return translate('AuthPlex'); } }, { key: 'oidc', get value() { return translate('AuthOidc'); } } ]; export const authenticationRequiredOptions = [ { key: 'enabled', get value() { return translate('Enabled'); } }, { key: 'disabledForLocalAddresses', get value() { return translate('DisabledForLocalAddresses'); } } ]; const certificateValidationOptions = [ { key: 'enabled', get value() { return translate('Enabled'); } }, { key: 'disabledForLocalAddresses', get value() { return translate('DisabledForLocalAddresses'); } }, { key: 'disabled', get value() { return translate('Disabled'); } } ]; const oauthData = { implementation: { value: 'PlexImport' }, configContract: { value: 'PlexListSettings' }, fields: [ { type: 'textbox', name: 'accessToken' }, { type: 'oAuth', name: 'signIn', value: 'startAuth' } ] }; class SecuritySettings extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isConfirmApiKeyResetModalOpen: false }; } // // Listeners onApikeyFocus = (event) => { event.target.select(); }; onResetApiKeyPress = () => { this.setState({ isConfirmApiKeyResetModalOpen: true }); }; onConfirmResetApiKey = () => { this.setState({ isConfirmApiKeyResetModalOpen: false }); this.props.onConfirmResetApiKey(); }; onCloseResetApiKeyModal = () => { this.setState({ isConfirmApiKeyResetModalOpen: false }); }; // // Render render() { const { settings, plexServersPopulated, isResettingApiKey, onInputChange } = this.props; const { authenticationMethod, authenticationRequired, username, password, plexAuthServer, plexRequireOwner, oidcClientId, oidcClientSecret, oidcAuthority, apiKey, certificateValidation } = settings; const authenticationEnabled = authenticationMethod && authenticationMethod.value !== 'none'; const showUserPass = authenticationMethod && ['basic', 'forms'].includes(authenticationMethod.value); const plexEnabled = authenticationMethod && authenticationMethod.value === 'plex'; const oidcEnabled = authenticationMethod && authenticationMethod.value === 'oidc'; return (
{translate('Authentication')} { authenticationEnabled ? {translate('AuthenticationRequired')} : null } { showUserPass && <> {translate('Username')} {translate('Password')} } { plexEnabled && <> {translate('PlexServer')} : 'Fetch'} name="plexAuth" provider="importList" providerData={oauthData} section="settings.importLists" onChange={onInputChange} /> ]} onChange={onInputChange} {...plexAuthServer} /> {translate('RestrictAccessToServerOwner')} } { oidcEnabled && <> {translate('Authority')} {translate('ClientId')} {translate('ClientSecret')} } {translate('ApiKey')} , ]} onChange={onInputChange} onFocus={this.onApikeyFocus} {...apiKey} /> {translate('CertificateValidation')}
); } } SecuritySettings.propTypes = { settings: PropTypes.object.isRequired, plexServersPopulated: PropTypes.bool.isRequired, isResettingApiKey: PropTypes.bool.isRequired, onInputChange: PropTypes.func.isRequired, onConfirmResetApiKey: PropTypes.func.isRequired }; export default SecuritySettings;