TokenView.jsx 1.51 KB
Newer Older
1 2 3 4 5 6 7
import React, { PureComponent } from 'react'
import {Navbar, Nav, NavItem, NavDropdown, MenuItem, Glyphicon, Jumbotron, Button} from 'react-bootstrap'
import {Row, Col, Collapse, FormControl, FormGroup, ControlLabel, HelpBlock, PanelGroup, Panel} from 'react-bootstrap'

import HostnameController from '../containers/HostnameController'
import ServerConfigController from '../containers/ServerConfigController'
import WhiteBox from './WhiteBox'
8
import jwtDecode from 'jwt-decode'
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

import moment from 'moment'
import 'moment/locale/nb';
// import 'moment/locale/en';

moment.locale("en");


export function expiresText(expires) {
  var expiresM = moment.unix(expires)
  return expiresM.fromNow()
}

class Component extends PureComponent {

24 25 26 27 28 29 30 31 32 33
  getIDTokenView(idtoken) {
    let str = JSON.stringify(jwtDecode(idtoken), undefined, 4)
    return (
      <div>
        <h4>ID Token decoded</h4>
        <pre>{str}</pre>
      </div>
    )
  }

34
  render() {
Andreas Åkre Solberg's avatar
Andreas Åkre Solberg committed
35
    // console.error("Component", this.props)
36 37 38 39 40 41 42

    if (!this.props.token) {
      return (
        <p>No token</p>
      )
    }

43
    let idtokenView = null
44 45
    let extxt = expiresText(this.props.token.expires)

46 47 48 49
    if (this.props.token.id_token) {
      idtokenView = this.getIDTokenView(this.props.token.id_token)
    }

50
    return (
51
      <Panel header="Access Token" eventKey="1" collapsible={true} defaultExpanded={true}>
52 53 54 55

        <p>This access token expires {extxt}</p>
        <pre>{this.props.tokenstring}</pre>

56 57
        {idtokenView}

58 59 60 61 62 63 64 65
      </Panel>
    )
  }


}

export default Component