Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshhmrc committed Jun 6, 2018
1 parent 170f8c3 commit 36770ba
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class HelpToSaveApiController @Inject()(http: WSHttp, authConnector: AuthConnect

var tokenCache: LoadingCache[String, String] = _

def loadCache(implicit hc: HeaderCarrier, request: Request[_]): LoadingCache[String, String] = {
def initializeCache(implicit hc: HeaderCarrier, request: Request[_]): LoadingCache[String, String] = {
if (tokenCache == null) {
logger.info("tokenCache is null, initializing it first time")
tokenCache =
CacheBuilder
.newBuilder
Expand All @@ -58,9 +59,12 @@ class HelpToSaveApiController @Inject()(http: WSHttp, authConnector: AuthConnect
}
}
})
}

tokenCache
tokenCache
} else {
logger.info("tokenCache is not null, means it was initialized already")
tokenCache
}
}

def availableEndpoints(): Action[AnyContent] = Action.async { implicit request =>
Expand All @@ -69,7 +73,7 @@ class HelpToSaveApiController @Inject()(http: WSHttp, authConnector: AuthConnect

def getCheckEligibilityPage(): Action[AnyContent] = Action.async { implicit request =>
Try {
loadCache
initializeCache
tokenCache.get("token")
} match {
case Success(token) =>
Expand All @@ -86,7 +90,7 @@ class HelpToSaveApiController @Inject()(http: WSHttp, authConnector: AuthConnect
}

def authorizeCallback(code: String): Action[AnyContent] = Action.async { implicit request =>
logger.info(s"inside authorizeCallback, code=$code")
logger.info(s"handling authorizeCallback from oauth")
http.post(s"${appConfig.oauthURL}/oauth/token", Json.parse(appConfig.tokenRequest(code)))
.map {
response =>
Expand Down

0 comments on commit 36770ba

Please sign in to comment.