This file contains hidden or 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 Impersonator(config: KeycloakConfig) | |
| (implicit sttpBackend: SttpBackend[Future, Nothing], ec: ExecutionContext) |
This file contains hidden or 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
| case class KeycloakConfig( | |
| authServerUrl: String, | |
| realm: String, | |
| impersonatorUsername: String, | |
| impersonatorPassword: String, | |
| clientId: String, | |
| redirectUri: String | |
| ) |
This file contains hidden or 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 scalacache._ | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scalacache.modes.scalaFuture._ | |
| implicit val cache: Cache[Token] = ??? | |
| def obtainTokenFor(userId: String): Future[(Token, Duration)] = ??? | |
| val userId = "123" |
This file contains hidden or 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
| def cachingWithTTL[T, M[_]](keyParts: Any*)(value: => M[(T, Duration)]) | |
| (implicit cache: Cache[T], mode: Mode[M], flags: Flags): M[T] = { | |
| import mode._ | |
| M.flatMap(get(keyParts:_*)) { | |
| case Some(found) => M.pure(found) | |
| case None => | |
| M.flatMap(value) { | |
| case (v, ttl) => | |
| M.map(put(keyParts:_*)(v, Some(ttl)))(_ => v) | |
| } |
This file contains hidden or 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
| $rootScope.authData = {}; | |
| $http.jsonp("http://localhost:9000/test?callback=JSON_CALLBACK") | |
| .success(function (response) { | |
| $rootScope.authData.token = response.token; | |
| $rootScope.authData.username = response.username; | |
| }); |
This file contains hidden or 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
| $rootScope.userLogout = function () { | |
| $cookies.remove('X-Authorization-Token'); | |
| $interval.cancel(updateTokenInterval); | |
| keycloak.logout(); | |
| }; |
This file contains hidden or 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
| var updateTokenInterval = $interval(function () { | |
| // refresh token if it's valid for less then 15 minutes | |
| keycloak.updateToken(15) | |
| .success(function (refreshed) { | |
| if (refreshed) { | |
| $cookies.put('X-Authorization-Token', keycloak.token); | |
| } | |
| }); | |
| }, 10000); |
This file contains hidden or 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
| implicit val system = ActorSystem("sso-system") | |
| implicit val actorMaterializer = ActorMaterializer() | |
| val oauth2 = new OAuth2Authorization( | |
| Logging(system, getClass), | |
| new KeycloakTokenVerifier( | |
| KeycloakDeploymentBuilder.build( | |
| getClass.getResourceAsStream("/keycloak.json") | |
| ) | |
| ) |