TokenView.jsx 1.64 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
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'
import jwtDecode from 'jwt-decode'

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 {

  getIDTokenView(idtoken) {
    let str = JSON.stringify(jwtDecode(idtoken), undefined, 4)
    return (
      <div>
        <h4>ID Token decoded</h4>
        <pre>{str}</pre>
      </div>
    )
  }

  render() {
    // console.error("Component", this.props)


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


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

    if (this.props.token.id_token) {
      idtokenView = this.getIDTokenView(this.props.token.id_token)
    }

    return (
Glenn Aarøen's avatar
Glenn Aarøen committed
53
54
55
56
57
58
59
60
61
62
      <Panel eventKey="1" collapsible={true} defaultExpanded={true}>
        <Panel.Heading className={"panel-title"}>
          Access Token
        </Panel.Heading>
        <Panel.Body>
          <p>This access token expires {extxt}</p>
          <pre>{this.props.tokenstring}</pre>

          {idtokenView}
        </Panel.Body>
63
64
65
66
67
68
69
70
      </Panel>
    )
  }


}

export default Component