ServerConfigInput.jsx 5.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
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)
12 13 14 15 16 17 18 19 20 21 22 23 24 25
    // console.log("--- props", this.props)

    // With these Location object properties you can access all of these URL components
    //
    // hash - Sets or returns the anchor portion of a URL.
    // host - Sets or returns the hostname and port of a URL.
    // hostname - Sets or returns the hostname of a URL.
    // href - Sets or returns the entire URL.
    // pathname - Sets or returns the path name of a URL.
    // port - Sets or returns the port number the server uses for a URL.
    // protocol - Sets or returns the protocol of a URL.
    // search - Sets or returns the query portion of a URL

    var currentURL = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '' ) + '/callback'
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
26
    // console.log("currentURL", currentURL)
27

28 29
    this.state = {
      clientId: "6233aedf-f08a-4112-9a1b-f33c3cd9b396",
30
      clientSecret: "",
31 32 33
      redirectURL: currentURL,
      scopes: "",
      response_type: "token"
34 35 36 37
    }
  }

  authenticateStart() {
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
38

39
    let config = Object.assign({}, this.props.serverConfig, this.state)
40
    // console.error("Authenticate", config, this.props.serverConfig, this.state)
41 42 43
    this.props.authenticateStart(config)
  }

44 45 46 47
  logoutStart() {
    this.props.logoutStart()
  }

48 49 50 51 52 53 54 55 56 57
  updateFieldHandler(field) {
    return (e) => {
      this.setState({
        [field]: e.target.value
      })
    }
  }


  render() {
58 59
    // console.log("X This props", this.props)
    // console.log("X This state", this.state)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    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
    }

75 76 77 78 79 80 81
    let userinfoEndpoint = ''
    if (this.state.userinfoEndpoint) {
      userinfoEndpoint = this.state.userinfoEndpoint
    } else if (this.props.serverConfig) {
      userinfoEndpoint = this.props.serverConfig.userinfo_endpoint
    }

82 83 84

    let expanded = !!this.props.serverConfig
    return (
85
      <Panel header="OAuth Server Configuration" eventKey="2" collapsible={true} defaultExpanded={expanded}>
86 87 88 89 90 91 92 93 94 95 96
        <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>

97 98 99 100 101
          <h4>Userinfo Endpoint</h4>
          <FormGroup>
              <FormControl type="text" value={userinfoEndpoint} onChange={this.updateFieldHandler.bind(this)("userinfo_endpoint")} />
          </FormGroup>

102 103 104 105 106 107 108 109 110 111
          <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>

112 113 114 115 116 117 118 119 120 121 122 123 124
          <h4>Scopes</h4>
          <FormGroup>
              <FormControl type="text" bsSize="large" value={this.state.scopes} onChange={this.updateFieldHandler.bind(this)("scopes")} />
          </FormGroup>

          <FormGroup controlId="response_type">
            <ControlLabel>Response Type</ControlLabel>
            <FormControl componentClass="select" placeholder="select" value={this.state.response_type} onChange={this.updateFieldHandler.bind(this)("response_type")}>
              <option value="token">OAuth Implicit Grant (token)</option>
              <option value="id_token token">OpenID Connect Implicit Flow (id_token token)</option>
            </FormControl>
          </FormGroup>

125 126
          <h4>Redirect URI</h4>
          <p>When you configure your client, please register the following redirect uri:</p>
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
127
          <p><code>{this.state.redirectURL}</code></p>
128 129 130 131 132

          <div>
            <Button onClick={this.authenticateStart.bind(this)} bsStyle="primary">
              <FontAwesome name='sign-in' /> Authenticate
            </Button>
133 134 135 136
            &nbsp;
            <Button onClick={this.logoutStart.bind(this)} bsStyle="danger">
              <FontAwesome name='sign-out' /> Wipe token
            </Button>
137 138 139 140 141 142 143 144 145
          </div>
        </form>
      </Panel>
    )
  }

}

export default Component