import React from "react" import PropTypes from "prop-types" export default class HttpAuth extends React.Component { static propTypes = { authorized: PropTypes.object, getComponent: PropTypes.func.isRequired, errSelectors: PropTypes.object.isRequired, schema: PropTypes.object.isRequired, name: PropTypes.string.isRequired, onChange: PropTypes.func } constructor(props, context) { super(props, context) let { name, schema } = this.props let value = this.getValue() this.state = { name: name, schema: schema, value: value } } getValue () { let { name, authorized } = this.props return authorized && authorized.getIn([name, "value"]) } onChange =(e) => { let { onChange } = this.props let { value, name } = e.target let newValue = Object.assign({}, this.state.value) if(name) { newValue[name] = value } else { newValue = value } this.setState({ value: newValue }, () => onChange(this.state)) } render() { let { schema, getComponent, errSelectors, name } = this.props const Input = getComponent("Input") const Row = getComponent("Row") const Col = getComponent("Col") const AuthError = getComponent("authError") const Markdown = getComponent("Markdown", true) const JumpToPath = getComponent("JumpToPath", true) const scheme = (schema.get("scheme") || "").toLowerCase() let value = this.getValue() let errors = errSelectors.allErrors().filter( err => err.get("authId") === name) if(scheme === "basic") { let username = value ? value.get("username") : null return

{ name || schema.get("name") }  (http, Basic)

{ username &&
Authorized
} { username ? { username } : } { username ? ****** : } { errors.valueSeq().map( (error, key) => { return } ) }
} if(scheme === "bearer") { return (

{ name || schema.get("name") }  (http, Bearer)

{ value &&
Authorized
} { value ? ****** : } { errors.valueSeq().map( (error, key) => { return } ) }
) } return
{name} HTTP authentication: unsupported scheme {`'${scheme}'`}
} }