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 December 5, 2018 21:30
the description for this gist
{
"alg" : "RS256",
"typ" : "JWT",
"kid" : "NgN92teIobiB0ayAJofvHPimh_l6EEImAtH8WJ-aBuc"
}
@kmikulski
kmikulski / post.sh
Created December 5, 2018 21:30
the description for this gist
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJOZ045MnRlSW9iaUIwYXlBSm9mdkhQaW1oX2w2RUVJbUF0SDhXSi1hQnVjIn0
.
eyJqdGkiOiI5ZGY3MjI0ZC1iOWNjLTQ1NzctODBlMS04NTUwYjE3ZTMxMDEiLCJleHAiOjE1MzkxMDMzMzEsIm5iZiI6MCwiaWF0IjoxNTM5MTA
zMDMxLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvTXlEZW1vIiwiYXVkIjoibXktcmVhY3QtY2xpZW50Iiwic3ViIj
oiYjY2Y2YyMTctYzAzMi00YjBjLWE3YzctYWViMjZjNGIyOTMxIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibXktcmVhY3QtY2xpZW50Iiwibm9uY
2UiOiI0ZWFjM2ZiMS1jZjlhLTQ0MzAtYjUzOC0wZmJhODY5MmVjNjMiLCJhdXRoX3RpbWUiOjE1MzkxMDMwMzAsInNlc3Npb25fc3RhdGUiOiIy
OGJkM2NhOC1hNWZhLTQxMDktOTAxMS01YTQ4NDZkNGI4ZDkiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q
6MzAwMCJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ij
p7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJuYW1lIjoiSmFrdWIgT
WlrdWxza2kiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJqb2huIiwiZ2l2ZW5fbmFtZSI6Ikpha3ViIiwiZmFtaWx5X25hbWUiOiJNaWt1bHNraSIs
@kmikulski
kmikulski / post.scala
Created December 5, 2018 21:30
the description for this gist
class UserRegistryActor extends Actor with ActorLogging {
import UserRegistryActor._
var users = Seq(
User("Grzegorz", 31, "Poland"),
User("Thomas", 28, "United Kingdom"))
def receive: Receive = {
case GetUsers => sender() ! Users(users)
// we won't need the remaining messages today
@kmikulski
kmikulski / post.scala
Created December 5, 2018 21:30
the description for this gist
object QuickstartServer extends App with UserRoutes with CORSHandler {
implicit def rejectionHandler: RejectionHandler = RejectionHandler.newBuilder().handle {
case AuthorizationFailedRejection => complete(StatusCodes.Unauthorized -> None)
}.result().mapRejectionResponse(addCORSHeaders)
lazy val routes: Route = corsHandler(userRoutes)
// rest of the boilerplate here
@kmikulski
kmikulski / post.scala
Created December 5, 2018 21:30
the description for this gist
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.model.{ HttpResponse, StatusCodes }
import akka.http.scaladsl.server.Directives.{ complete, options, respondWithHeaders, _ }
import akka.http.scaladsl.server.{ Directive0, Route }
trait CORSHandler {
private val corsResponseHeaders = List(
`Access-Control-Allow-Origin`.*,
@kmikulski
kmikulski / post.scala
Created December 5, 2018 21:30
the description for this gist
libraryDependencies ++= Seq(
"org.keycloak" % "keycloak-core" % "4.0.0.Final",
"org.keycloak" % "keycloak-adapter-core" % "4.0.0.Final",
"org.jboss.logging" % "jboss-logging" % "3.3.0.Final",
"org.apache.httpcomponents" % "httpclient" % "4.5.1",
// rest of dependencies here
)
@kmikulski
kmikulski / post.jsx
Created December 5, 2018 21:30
the description for this gist
authorizationHeader() {
if(this.props.keycloak) return {
headers: {
"Authorization": "Bearer " + this.props.keycloak.token
}
}; else return {};
}
@kmikulski
kmikulski / post.jsx
Created December 5, 2018 21:30
the description for this gist
import React, { Component } from 'react';
class APIResponse extends Component {
render() {
if(this.props.response)
return ( <pre>{this.props.response}</pre> );
else
return (<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';
import UserInfo from './UserInfo';
import Logout from './Logout';
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
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom'
class Logout extends Component {
logout() {
this.props.history.push('/');
this.props.keycloak.logout();
}