Skip to content

Instantly share code, notes, and snippets.

View kmikulski's full-sized avatar

Jakub Mikulski kmikulski

  • Kraków, Poland
View GitHub Profile
@kmikulski
kmikulski / post.json
Created June 7, 2018 17:41
the description for this gist
"dependencies": {
...
"react-router-dom": "^4.2.2",
"keycloak-js": "4.0.0-beta.2"
}
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:41
the description for this gist
import React, { Component } from 'react';
import { BrowserRouter, Route, Link } from 'react-router-dom';
import Welcome from './Welcome';
import Secured from './Secured';
import './App.css';
class App extends Component {
render() {
return (
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
import React, { Component } from 'react';
class Welcome extends Component {
render() {
return (
<div className="Welcome">
<p>This is your public-facing component.</p>
</div>
);
}
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
import React, { Component } from 'react';
import Keycloak from 'keycloak-js';
class Secured extends Component {
constructor(props) {
super(props);
this.state = { keycloak: null, authenticated: false };
}
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
const keycloak = Keycloak('/keycloak.json');
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
const keycloak = Keycloak({
realm: "MyDemo",
auth-server-url: "http://localhost:8080/auth",
ssl-required: "external",
resource: "my-react-client",
public-client: true,
confidential-port: 0
});
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
keycloak.init({onLoad: 'login-required'}).then(authenticated => {
this.setState({ keycloak: keycloak, authenticated: authenticated })
})
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
import React, { Component } from 'react';
class UserInfo extends Component {
constructor(props) {
super(props);
this.state = {
name: "",
email: "",
id: ""
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom'
class Logout extends Component {
logout() {
this.props.history.push('/');
this.props.keycloak.logout();
}
@kmikulski
kmikulski / post.jsx
Created June 7, 2018 17:42
the description for this gist
import React, { Component } from 'react';
import Keycloak from 'keycloak-js';
import UserInfo from './UserInfo';
import Logout from './Logout';
class Secured extends Component {
constructor(props) {
super(props);
this.state = { keycloak: null, authenticated: false };