ServerConfigInput.jsx 2.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
import React, { PureComponent } from 'react'
import {Alert, InputGroup, Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap'
import {Panel, Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock} from 'react-bootstrap'
import FontAwesome from 'react-fontawesome'

import WhiteBox from './WhiteBox'

class Component extends PureComponent {

  constructor(props) {
    super(props)
    console.log("--- props", this.props)
    this.state = {
      clientId: "6233aedf-f08a-4112-9a1b-f33c3cd9b396",
      clientSecret: "af85a0f0-2c68-421d-8228-a6c83628de19"
    }
  }

  authenticateStart() {
    console.error("Authenticate")
    let config = Object.assign({}, this.props.serverConfig, this.state)
    this.props.authenticateStart(config)
  }

  updateFieldHandler(field) {
    return (e) => {
      this.setState({
        [field]: e.target.value
      })
    }
  }


  render() {
    console.log("X This state", this.props)
    console.log("X This state", this.state)

    let authorizationEndpoint = ''
    if (this.state.authorizationEndpoint) {
      authorizationEndpoint = this.state.authorizationEndpoint
    } else if (this.props.serverConfig) {
      authorizationEndpoint = this.props.serverConfig.authorization_endpoint
    }

    let tokenEndpoint = ''
    if (this.state.tokenEndpoint) {
      tokenEndpoint = this.state.tokenEndpoint
    } else if (this.props.serverConfig) {
      tokenEndpoint = this.props.serverConfig.token_endpoint
    }


    let expanded = !!this.props.serverConfig
    return (
      <Panel header="OAuth Server Configuration" eventKey="2" collapsible={true} expanded={expanded}>
        <form>
          <h4>OAuth Authorization endpoint</h4>
          <FormGroup>
              <FormControl type="text" value={authorizationEndpoint} onChange={this.updateFieldHandler.bind(this)("authorizationEndpoint")} />
          </FormGroup>

          <h4>OAuth Token endpoint</h4>
          <FormGroup>
              <FormControl type="text" value={tokenEndpoint} onChange={this.updateFieldHandler.bind(this)("tokenEndpoint")} />
          </FormGroup>

          <h4>Client ID</h4>
          <FormGroup>
              <FormControl type="text" bsSize="large" value={this.state.clientId} onChange={this.updateFieldHandler.bind(this)("clientId")} />
          </FormGroup>

          <h4>Client secret</h4>
          <FormGroup>
              <FormControl type="text" bsSize="large" value={this.state.clientSecret} onChange={this.updateFieldHandler.bind(this)("clientSecret")} />
          </FormGroup>

          <h4>Redirect URI</h4>
          <p>When you configure your client, please register the following redirect uri:</p>
          <p><code>http://localhost:8080/callback</code></p>

          <div>
            <Button onClick={this.authenticateStart.bind(this)} bsStyle="primary">
              <FontAwesome name='sign-in' /> Authenticate
            </Button>
          </div>
        </form>
      </Panel>
    )
  }

}

export default Component