This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"alg" : "RS256", | |
"typ" : "JWT", | |
"kid" : "NgN92teIobiB0ayAJofvHPimh_l6EEImAtH8WJ-aBuc" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJOZ045MnRlSW9iaUIwYXlBSm9mdkhQaW1oX2w2RUVJbUF0SDhXSi1hQnVjIn0 | |
. | |
eyJqdGkiOiI5ZGY3MjI0ZC1iOWNjLTQ1NzctODBlMS04NTUwYjE3ZTMxMDEiLCJleHAiOjE1MzkxMDMzMzEsIm5iZiI6MCwiaWF0IjoxNTM5MTA | |
zMDMxLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvTXlEZW1vIiwiYXVkIjoibXktcmVhY3QtY2xpZW50Iiwic3ViIj | |
oiYjY2Y2YyMTctYzAzMi00YjBjLWE3YzctYWViMjZjNGIyOTMxIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibXktcmVhY3QtY2xpZW50Iiwibm9uY | |
2UiOiI0ZWFjM2ZiMS1jZjlhLTQ0MzAtYjUzOC0wZmJhODY5MmVjNjMiLCJhdXRoX3RpbWUiOjE1MzkxMDMwMzAsInNlc3Npb25fc3RhdGUiOiIy | |
OGJkM2NhOC1hNWZhLTQxMDktOTAxMS01YTQ4NDZkNGI4ZDkiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q | |
6MzAwMCJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ij | |
p7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJuYW1lIjoiSmFrdWIgT | |
WlrdWxza2kiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJqb2huIiwiZ2l2ZW5fbmFtZSI6Ikpha3ViIiwiZmFtaWx5X25hbWUiOiJNaWt1bHNraSIs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`.*, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authorizationHeader() { | |
if(this.props.keycloak) return { | |
headers: { | |
"Authorization": "Bearer " + this.props.keycloak.token | |
} | |
}; else return {}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class APIResponse extends Component { | |
render() { | |
if(this.props.response) | |
return ( <pre>{this.props.response}</pre> ); | |
else | |
return (<div/>); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { withRouter } from 'react-router-dom' | |
class Logout extends Component { | |
logout() { | |
this.props.history.push('/'); | |
this.props.keycloak.logout(); | |
} |